| // LCD module connections |
| sbit LCD_RS at RB0_bit; |
| sbit LCD_EN at RB1_bit; |
| sbit LCD_D4 at RB2_bit; |
| sbit LCD_D5 at RB3_bit; |
| sbit LCD_D6 at RB4_bit; |
| sbit LCD_D7 at RB5_bit; |
| sbit LCD_RS_Direction at TRISB0_bit; |
| sbit LCD_EN_Direction at TRISB1_bit; |
| sbit LCD_D4_Direction at TRISB2_bit; |
| sbit LCD_D5_Direction at TRISB3_bit; |
| sbit LCD_D6_Direction at TRISB4_bit; |
| sbit LCD_D7_Direction at TRISB5_bit; |
| // End LCD module connections |
| char hs; char duty1; char duty2;char x=0; |
| void main() { |
| adcon1=7; |
| trisa=0b00111101;trisb=0b10000000;trisc=0b00000000;trisd=0b00000000; |
| porta=0;portb=0;portc=0;portd=0; |
| UART1_Init(9600); // Initialize UART module at 9600 bps |
| Delay_ms(100); // Wait for UART module to stabilize |
| PWM1_Init(5000); // Initialize PWModule at 5KHz |
| PWM2_Init(5000); |
| PWM1_Start(); // start PWM1 |
| PWM2_Start(); // start PWM2 |
| Lcd_Init(); // Initialize LCD |
| Lcd_Cmd(_LCD_CLEAR); // Clear display |
| Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off |
| Lcd_Out(1,4,"salvum car"); |
| Lcd_Out(2,3,"sama+haneen"); |
| delay_ms(4000); |
| Lcd_Cmd(_LCD_CLEAR); |
| loop: |
| if (UART1_Data_Ready()) {hs = UART1_Read();} |
| if(hs==48){PWM1_Set_Duty(0);PWM2_Set_Duty(0);} |
| if(hs==49){PWM1_Set_Duty(150);PWM2_Set_Duty(150);} |
| if(hs==50){PWM1_Set_Duty(150);PWM2_Set_Duty(150);} |
| if(hs==51){PWM1_Set_Duty(175);PWM2_Set_Duty(175);} |
| if(hs==52){PWM1_Set_Duty(175);PWM2_Set_Duty(175);} |
| if(hs==53){PWM1_Set_Duty(200);PWM2_Set_Duty(200);} |
| if(hs==54){PWM1_Set_Duty(200);PWM2_Set_Duty(200);} |
| if(hs==55){PWM1_Set_Duty(225);PWM2_Set_Duty(225);} |
| if(hs==56){PWM1_Set_Duty(225);PWM2_Set_Duty(225);} |
| if(hs==57){PWM1_Set_Duty(255);PWM2_Set_Duty(255);} |
| if(hs=='q'){PWM1_Set_Duty(255);PWM2_Set_Duty(255);} |
| if(hs=='F'){portd.f0=1;portd.f2=1; } |
| if(hs=='B'){portd.f1=1;portd.f3=1; } |
| if(hs=='R'){portd.f0=1;portd.f3=1; } |
| if(hs=='L'){portd.f1=1;portd.f2=1; } |
| if(hs=='S'){portd.f0=0;portd.f1=0;portd.f2=0;portd.f3=0;delay_ms(5); } |
| if(hs=='W'){portd.f6=1;} |
| if(hs=='w'){portd.f6=0;} |
| if(hs=='U'){portd.f5=1;} |
| if(hs=='u'){portd.f5=0;} |
| if(hs=='V'){portd.f4=1;} |
| if(hs=='v'){portd.f4=0;} |
| if(hs=='o'){loop5: |
| if(porta.f0==1){portd.f1=1;portd.f2=1;delay_ms(200);portd.f2=0;portd.f1=0;delay_ms(200);} |
| if(portb.f7==1){portd.f0=1;portd.f3=1;delay_ms(200);portd.f0=0;portd.f3=0;delay_ms(200);} |
| if (UART1_Data_Ready()) {hs = UART1_Read();} |
| if(hs=='y'){goto loop;} |
| goto loop5; |
| } |
| if(hs=='X'){while(porta.f2==0){PWM1_Set_Duty(255);PWM2_Set_Duty(255);portd.f0=1;portd.f2=1;} |
| loop2: |
| PWM1_Set_Duty(125);PWM2_Set_Duty(125); |
| if (UART1_Data_Ready()) {hs = UART1_Read();} |
| if(hs=='x') |
| {portd.f0=0;portd.f1=0;portd.f2=0;portd.f3=0;delay_ms(5);PWM1_Set_Duty(255);PWM2_Set_Duty(255);delay_ms(200);goto loop; } |
| goto loop2; |
| } |
| if(porta.f3==1){PWM1_Set_Duty(125);PWM2_Set_Duty(125); |
| for(x=0;x<5;x++){portd.f4=1;portd.f5=1;portd.f6=1;delay_ms(150);portd.f4=0;portd.f5=0;portd.f6=0;delay_ms(150);} |
| portd.f0=0;portd.f1=0;portd.f2=0;portd.f3=0;delay_ms(3000); |
| PWM1_Set_Duty(255);PWM2_Set_Duty(255);} |
| goto loop; |
| } |