0% found this document useful (0 votes)
25 views1 page

UART

This code initializes a UART module to communicate at 9600 bps. It then enters a loop where it checks for received data. If data is received, it reads the data and sends it back out over UART. It also checks different switch states and controls LEDs connected to different ports based on the received character.

Uploaded by

izaias jr
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views1 page

UART

This code initializes a UART module to communicate at 9600 bps. It then enters a loop where it checks for received data. If data is received, it reads the data and sends it back out over UART. It also checks different switch states and controls LEDs connected to different ports based on the received character.

Uploaded by

izaias jr
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

pic020_v001.

c 25/01/2018 14:00:51

1: char uart_rd;
2:
3: void main() {
4: //ANSEL = 0; // Configure AN pins as digital
5: //ANSELH = 0;
6: ADCON0 = 0x00;
7: ADCON1 = 0x06;
8: CMCON = 0x07;
9: TRISB = 0x80;
10: PORTB = 0x00;
11: UART1_Init(9600); // Initialize UART module at 9600 bps
12: Delay_ms(100); // Wait for UART module to stabilize
13: RB6_bit = 0x01;
14: UART1_Write_Text("Start");
15: UART1_Write(10);
16: UART1_Write(13);
17:
18: while (1) { // Endless loop
19: if (UART1_Data_Ready()) { // If data is received,
20: uart_rd = UART1_Read(); // read the received data,
21: UART1_Write(uart_rd); // and send data via UART
22: switch(uart_rd)
23: {
24: case 'y': RB0_bit = 0x01; break;
25: case 't': RB0_bit = 0x00; break;
26: case 'r': RB1_bit = 0x01; break;
27: case 'e': RB1_bit = 0x00; break;
28: case 'g': RB2_bit = 0x01; break;
29: case 'f': RB2_bit = 0x00; break;
30:
31: }
32:
33:
34: }
35:
36: if(RB7_bit)
37: {
38: UART1_Write_Text("Alert!");
39: // UART1_Write(10);
40: UART1_Write(13);
41: }
42: }
43: }

1/1 mikroC PRO for PIC by mikroElektronika

You might also like