Devre şeması bir öncekinin aynısı tek fark pot eklendi.
Kod;
sbit LCD_RS at RC6_bit;
sbit LCD_EN at RC7_bit;
sbit LCD_D7 at RD4_bit;
sbit LCD_D6 at RD3_bit;
sbit LCD_D5 at RD2_bit;
sbit LCD_D4 at RD1_bit;
sbit LCD_EN at RC7_bit;
sbit LCD_D7 at RD4_bit;
sbit LCD_D6 at RD3_bit;
sbit LCD_D5 at RD2_bit;
sbit LCD_D4 at RD1_bit;
// Pin direction
sbit LCD_RS_Direction at TRISC6_bit;
sbit LCD_EN_Direction at TRISC7_bit;
sbit LCD_D7_Direction at TRISD4_bit;
sbit LCD_D6_Direction at TRISD3_bit;
sbit LCD_D5_Direction at TRISD2_bit;
sbit LCD_D4_Direction at TRISD1_bit;
sbit LCD_RS_Direction at TRISC6_bit;
sbit LCD_EN_Direction at TRISC7_bit;
sbit LCD_D7_Direction at TRISD4_bit;
sbit LCD_D6_Direction at TRISD3_bit;
sbit LCD_D5_Direction at TRISD2_bit;
sbit LCD_D4_Direction at TRISD1_bit;
void init_ayarlar(){
TRISC.RC2=0; // FULL-BRIDGE CIKISLARI ICIN AYARLAMALAR
PORTC.RC2=0;
TRISD.RD5=0;
TRISD.RD6=0;
TRISD.RD7=0;
PORTD.RD5=0;
TRISD.RD6=0;
TRISD.RD7=0;
TRISB.RB5=1;
PORTB.RB5=0;
TRISB.RB6=1;
PORTB.RB6=0;
TRISB.RB7=0;
PORTB.RB7=1;
PR2 = 0b11111001 ;
T2CON = 0b00000101 ;
CCPR1L = 0b00000000;
CCP1CON= 0b11011100; // Full Bridge Forward; P1A, P1C active-high; P1B, P1D active-high
TRISC.RC2=0; // FULL-BRIDGE CIKISLARI ICIN AYARLAMALAR
PORTC.RC2=0;
TRISD.RD5=0;
TRISD.RD6=0;
TRISD.RD7=0;
PORTD.RD5=0;
TRISD.RD6=0;
TRISD.RD7=0;
TRISB.RB5=1;
PORTB.RB5=0;
TRISB.RB6=1;
PORTB.RB6=0;
TRISB.RB7=0;
PORTB.RB7=1;
PR2 = 0b11111001 ;
T2CON = 0b00000101 ;
CCPR1L = 0b00000000;
CCP1CON= 0b11011100; // Full Bridge Forward; P1A, P1C active-high; P1B, P1D active-high
ECCP1AS.ECCPAS2=0;
ECCP1AS.ECCPAS1=0;
ECCP1AS.ECCPAS0=0;
trisa.rb0=1;
ECCP1AS.ECCPAS1=0;
ECCP1AS.ECCPAS0=0;
trisa.rb0=1;
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
/* Init ADC */
ADCON0=0X00; // Select Left justify result. ADC port channel 0
ADCON1 &=0xfE; // Select the FRC for 8 MHz
ADON_bit=1; // Turn on the ADC conversion module
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
/* Init ADC */
ADCON0=0X00; // Select Left justify result. ADC port channel 0
ADCON1 &=0xfE; // Select the FRC for 8 MHz
ADON_bit=1; // Turn on the ADC conversion module
}
unsigned int ipwm=0;
unsigned char txt[4];
unsigned int duty;
unsigned int dutyy;
char txt1[7];
void main() {
init_ayarlar();
while(1){
if (portb.rb5){
CCPR1L = 0b0000000;
delay_ms(100);
P1M1_BIT=0;
P1M0_BIT=1;
PORTB.RB7=0;
while(portb.rb5);
}
if (portb.rb6){
CCPR1L = 0b0000000;
delay_ms(100);
P1M1_BIT=1;
P1M0_BIT=1;
PORTB.RB7=1;
while(portb.rb6);
}
GO_DONE_bit=1; // initiate conversion on the channel 0
while(GO_DONE_bit) continue; // Wait conversion done
ipwm = ADRESH; // Get the highest 8 bit MSB result, ignore the 2 bit LSB
if(ipwm>248) ipwm=248; // sinir değer bunu aşarsa donma oluyor.
if(ipwm<=0) ipwm=0;
CCPR1L=ipwm; // Set the Duty Cycle base on the ADC result
duty=ipwm*100/248;
dutyy=ipwm<<2;
dutyy+=ADRESL>>6;
inttostr(dutyy,txt1);
LCD_OUT(1,1,"CCPR1L+CCP1CON:");
LCD_OUT(2,1,txt1);
inttostr(ipwm,txt);
LCD_OUT(1,1,txt);
unsigned int ipwm=0;
unsigned char txt[4];
unsigned int duty;
unsigned int dutyy;
char txt1[7];
void main() {
init_ayarlar();
while(1){
if (portb.rb5){
CCPR1L = 0b0000000;
delay_ms(100);
P1M1_BIT=0;
P1M0_BIT=1;
PORTB.RB7=0;
while(portb.rb5);
}
if (portb.rb6){
CCPR1L = 0b0000000;
delay_ms(100);
P1M1_BIT=1;
P1M0_BIT=1;
PORTB.RB7=1;
while(portb.rb6);
}
GO_DONE_bit=1; // initiate conversion on the channel 0
while(GO_DONE_bit) continue; // Wait conversion done
ipwm = ADRESH; // Get the highest 8 bit MSB result, ignore the 2 bit LSB
if(ipwm>248) ipwm=248; // sinir değer bunu aşarsa donma oluyor.
if(ipwm<=0) ipwm=0;
CCPR1L=ipwm; // Set the Duty Cycle base on the ADC result
duty=ipwm*100/248;
dutyy=ipwm<<2;
dutyy+=ADRESL>>6;
inttostr(dutyy,txt1);
LCD_OUT(1,1,"CCPR1L+CCP1CON:");
LCD_OUT(2,1,txt1);
inttostr(ipwm,txt);
LCD_OUT(1,1,txt);
}
}
}
Sonuç
Hiç yorum yok:
Yorum Gönder