Advertisement
FahmiG

Wireless Counter B

Oct 17th, 2014
1,344
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.44 KB | None | 0 0
  1.  /* Wireless counter
  2. PIC B  duplicating data on PIC A
  3.  
  4. Code for this video:
  5. https://www.youtube.com/watch?v=pm_PA_DsWZY
  6. */
  7.  
  8. char uart_rd;
  9. char txt[7];
  10.  
  11. // LCD module connections
  12. sbit LCD_RS at RB5_bit;
  13. sbit LCD_EN at RB6_bit;
  14. sbit LCD_D4 at RB0_bit;
  15. sbit LCD_D5 at RB1_bit;
  16. sbit LCD_D6 at RB2_bit;
  17. sbit LCD_D7 at RB3_bit;
  18.  
  19. sbit LCD_RS_Direction at TRISB5_bit;
  20. sbit LCD_EN_Direction at TRISB6_bit;
  21. sbit LCD_D4_Direction at TRISB0_bit;
  22. sbit LCD_D5_Direction at TRISB1_bit;
  23. sbit LCD_D6_Direction at TRISB2_bit;
  24. sbit LCD_D7_Direction at TRISB3_bit;
  25. // End LCD module connections
  26.  
  27. //Count variable
  28. int Count = 0;
  29.  
  30. void main()
  31. {
  32.       UART1_Init(9600); // Initialize UART module at 9600 bps
  33.       Delay_ms(100);    // Wait for UART module to stabilize
  34.  
  35.       TRISD=0;      //set portD as LED output
  36.       TRISC=0;
  37.  
  38.        Lcd_Init();                 // Initialize LCD
  39.        Lcd_Cmd(_LCD_CLEAR);        // Clear display
  40.        Lcd_Cmd(_LCD_CURSOR_OFF);   // Cursor off
  41.        Lcd_Out(1,1, "    Welcome");
  42.  
  43.  
  44.      //Blink All LED Twice
  45.      PORTD=255;
  46.      Delay_ms(500);
  47.      PORTD=0;
  48.      Delay_ms(500);
  49.      PORTD=255;
  50.      Delay_ms(500);
  51.      PORTD=0;
  52.  
  53.        Lcd_Cmd(_LCD_CLEAR);        // Clear display
  54.        Lcd_Out(1,1, "Count: ");
  55.  
  56.         Count = 0;
  57.  
  58.         Delay_ms(1000);
  59.         Lcd_Cmd(_LCD_CLEAR);
  60.         UART1_Write('R');   //Request current count from PIC A
  61.  
  62.  
  63.  
  64.      while(1)
  65.      {
  66.             if (UART1_Data_Ready())  // If data is received
  67.             {
  68.                   uart_rd= UART1_Read();     // read the received data,
  69.  
  70.                   if( uart_rd=='a')
  71.                   {
  72.                       Count++;
  73.                       Lcd_Cmd(_LCD_CLEAR);
  74.                       Lcd_Out(1, 1, "Count: ");    // Write on LCD
  75.                       IntToStr(Count, txt);   //display count value at LCD
  76.                       Lcd_Out(1,8,txt);
  77.                       Delay_ms(100);
  78.  
  79.                   }
  80.  
  81.  
  82.  
  83.                   if(uart_rd=='C')    //Clear count
  84.                   {
  85.                        Count = 0;
  86.                        Lcd_Out(1, 1, "Reset Counter");    // Write on LCD
  87.                        Delay_ms(1000);
  88.                        Lcd_Cmd(_LCD_CLEAR);        // Clear display
  89.                   }
  90.  
  91.             }
  92.            
  93.                      //dispaly count on LED in binary format
  94.                      PORTD = Count ;
  95.  
  96.  
  97.      } //End of while(1)
  98. }   // End of main function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement