Advertisement
Guest User

Untitled

a guest
Sep 19th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.61 KB | None | 0 0
  1. void LeftMotor(int,int,int);
  2. void RightMotor(int,int,int);
  3. void NumaleeSong(void);
  4. unsigned char ir_cmd=0;
  5.  
  6. //------------------ Interrupt service routine INT -----------------//
  7. void interrupt(){
  8. unsigned char i;               // Keep counter
  9. if(INTCON.INTF)                // Check interrupt flag RB0 (Falling edge)
  10. {
  11. Delay_us(416);                 // Delay 1/2 of 1 bit timing
  12. // (baudrate 1200 bps)
  13. for(i=0;i<8;i++)               // Loop 8 times for keep data from ER-4
  14. {
  15. Delay_us(833);                // Delay of 1 bit timing
  16. // (baudrate 1200 bps)
  17. ir_cmd = ir_cmd>>1;           // Shitt bit 1 time
  18. if((PORTB & 0x01)==1)         // Get logic @ RB0 = '1'?
  19. ir_cmd = ir_cmd | 0x80;       // Inset bit data is '1'
  20. }
  21. Delay_us(833);                // Delay of 1 bit timing
  22. // (baudrate 1200 bps)
  23. INTCON.INTF =0;               // Clear interrupt flag
  24. }
  25. }
  26. //------------------ Function for get character from Remote ---------//
  27. unsigned char get_remote()
  28. {
  29. unsigned char _key=ir_cmd;  // Get character to buffer
  30. ir_cmd=0;                   // Clear old data
  31. return(_key);
  32. // Return character from Remote
  33. }
  34.  
  35. void main()
  36. {
  37. unsigned char key;                           // Save Remote Key Press
  38. ANSELH.F4 = 0;
  39. ///////////////Left Motor Connection/////////
  40. TRISD.F0 = 0;
  41. TRISD.F1 = 0;
  42. TRISC.F2 = 0;
  43. ///////////End Left Motor Connection/////////
  44. ANSELH = 0x00;                              //Set Port B Logic Status
  45. ///////////////Right Motor Connection///////
  46. TRISB.F1 = 0;
  47. TRISB.F2 = 0;
  48. TRISC.F1 = 0;
  49. ///////////End Right Motor Connection/////////
  50. Lcd_Init(&PORTD);                          //LCD Connection
  51. TRISB.F3 = 0;                              //LED Connection
  52. Sound_Init(&PORTc,0);                      //Speaker Connection
  53. while(1)
  54. {
  55.   Lcd_Cmd(LCD_CLEAR);
  56.   key = get_remote();
  57.   if(key=='a' || key=='A') //if press A then backward
  58.   {
  59.       Lcd_Out(1,4,"Backward");
  60.       LeftMotor(0,1,1);
  61.       RightMotor(0,1,1);
  62.       Sound_Play(2000,500);
  63.       Delay_ms(100);
  64.       Sound_Play(2000,500);
  65.   }
  66.   else if(key=='b' || key=='B') //if press B then turn right
  67.   {
  68.       Lcd_Out(1,3,"Turn Right");
  69.       LeftMotor(1,0,1);
  70.       RightMotor(1,1,1);
  71.   }
  72.   else if(key=='c' || key=='C') //if press C then turn left
  73.   {
  74.       Lcd_Out(1,4,"Turn Left");
  75.       LeftMotor(1,1,1);
  76.       RightMotor(1,0,1);
  77.   }
  78.   else if(key=='d' || key=='D') //if press D then go straight
  79.   {
  80.       Lcd_Out(1,3,"Go Straight");
  81.       LeftMotor(1,0,1);
  82.       RightMotor(1,0,1);
  83.   }
  84.   else
  85.   {
  86.       Lcd_Out(1,3,"Stop !!!"); //if don't press any button then stop all motor
  87.       LeftMotor(1,1,1);
  88.       RightMotor(1,1,1);
  89.   }
  90. }
  91. }
  92.  
  93. void LeftMotor(int x,int y,int z){
  94. PORTD.F0 = x;
  95. PORTD.F1 = y;
  96. PORTC.F2 = z;
  97. }
  98. void RightMotor(int x,int y,int z){
  99. PORTB.F1 = x;
  100. PORTB.F2 = y;
  101. PORTC.F1 = z;
  102. }
  103.  
  104. void NumaleeSong(){
  105.       Sound_Play(1975.5,250);
  106.       Sound_Play(1760,250);
  107.       Sound_Play(1568,250);
  108.       Sound_Play(1760,250);
  109.       Sound_Play(1975.5,250);
  110.       Sound_Play(1975.5,250);
  111.       Sound_Play(1975.5,250);
  112.       Delay_ms(250);
  113.       Sound_Play(1760.0,250);
  114.       Sound_Play(1760.0,250);
  115.       Sound_Play(1760.0,250);
  116.       Delay_ms(250);
  117.       Sound_Play(1975.5,250);
  118.       Sound_Play(2349.3,250);
  119.       Sound_Play(2349.3,250);
  120.       Delay_ms(250);
  121.       Sound_Play(1975.5,250);
  122.       Sound_Play(1760,250);
  123.       Sound_Play(1568,250);
  124.       Sound_Play(1760,250);
  125.       Sound_Play(1975.5,250);
  126.       Sound_Play(1975.5,250);
  127.       Sound_Play(1975.5,250);
  128.       Delay_ms(250);
  129.       Sound_Play(1760,250);
  130.       Sound_Play(1760,250);
  131.       Sound_Play(1975.5,250);
  132.       Sound_Play(1568.0,250);
  133. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement