Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Wireless counter
- PIC B duplicating data on PIC A
- Code for this video:
- https://www.youtube.com/watch?v=pm_PA_DsWZY
- */
- char uart_rd;
- char txt[7];
- // LCD module connections
- sbit LCD_RS at RB5_bit;
- sbit LCD_EN at RB6_bit;
- sbit LCD_D4 at RB0_bit;
- sbit LCD_D5 at RB1_bit;
- sbit LCD_D6 at RB2_bit;
- sbit LCD_D7 at RB3_bit;
- sbit LCD_RS_Direction at TRISB5_bit;
- sbit LCD_EN_Direction at TRISB6_bit;
- sbit LCD_D4_Direction at TRISB0_bit;
- sbit LCD_D5_Direction at TRISB1_bit;
- sbit LCD_D6_Direction at TRISB2_bit;
- sbit LCD_D7_Direction at TRISB3_bit;
- // End LCD module connections
- //Count variable
- int Count = 0;
- void main()
- {
- UART1_Init(9600); // Initialize UART module at 9600 bps
- Delay_ms(100); // Wait for UART module to stabilize
- TRISD=0; //set portD as LED output
- TRISC=0;
- Lcd_Init(); // Initialize LCD
- Lcd_Cmd(_LCD_CLEAR); // Clear display
- Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
- Lcd_Out(1,1, " Welcome");
- //Blink All LED Twice
- PORTD=255;
- Delay_ms(500);
- PORTD=0;
- Delay_ms(500);
- PORTD=255;
- Delay_ms(500);
- PORTD=0;
- Lcd_Cmd(_LCD_CLEAR); // Clear display
- Lcd_Out(1,1, "Count: ");
- Count = 0;
- Delay_ms(1000);
- Lcd_Cmd(_LCD_CLEAR);
- UART1_Write('R'); //Request current count from PIC A
- while(1)
- {
- if (UART1_Data_Ready()) // If data is received
- {
- uart_rd= UART1_Read(); // read the received data,
- if( uart_rd=='a')
- {
- Count++;
- Lcd_Cmd(_LCD_CLEAR);
- Lcd_Out(1, 1, "Count: "); // Write on LCD
- IntToStr(Count, txt); //display count value at LCD
- Lcd_Out(1,8,txt);
- Delay_ms(100);
- }
- if(uart_rd=='C') //Clear count
- {
- Count = 0;
- Lcd_Out(1, 1, "Reset Counter"); // Write on LCD
- Delay_ms(1000);
- Lcd_Cmd(_LCD_CLEAR); // Clear display
- }
- }
- //dispaly count on LED in binary format
- PORTD = Count ;
- } //End of while(1)
- } // End of main function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement