PIC16f690 uart to LED

Thread Starter

adulfo

Joined Feb 10, 2010
6
Hi guys, can anybody can help me in creating the code for a program that will get data from serial(UART) that can light up an LED when the pulse transmitted is high and "off" if its low using PIC16F690. I am using a C compiler. Thanks
 

Tahmid

Joined Jul 2, 2008
343
Which C compiler are you using?
If you use mikroC, there are internal library functions made for this. I don't know about other C compilers.
 

Thread Starter

adulfo

Joined Feb 10, 2010
6
I have microC. I will go over it. Another question about the PIC16f690, can we use the ADC and UART simultaneously? I want to send the digital output from the two sensors to the Host PC. Just give me an idea also on how to send a code to the PIC that would make a certain I/O port to be in high/low depending on the received pulse. I have the initial configuration of the UART, but I don't know how to get the data from the RCREG to be outputted on a I/O pin of the MCU. Thanks again for the help.
 

Tahmid

Joined Jul 2, 2008
343
Hi adulfo,
You can use both the ADC and UART modules. Take the ADC readings and send via UART. Then read data from UART and write to PORT accordingly.

Something like this:
Rich (BB code):
   int R1, R2;
    USART_Init(9600); //9600bps
    R1 = ADC_Read(0)>>2; //Read CH0 (8-bit)
    R2 = ADC_Read(2)>>2; //Read CH1 (8-bit)
    USART_Write(R1); //Send reading1
    delay_ms(1); //Wait for 1ms
    USART_Write(R2); //Send reading2
//This would be the reading from ADC and sending to PC part.
//This would just send the readings, nothing else
//This code is for mikroC v8.2, I don't know about other versions
Rich (BB code):
   unsigned char R3;
   if (USART_Data_Ready()){
      R3 = USART_Read();
      PORTD = R3;
   }
//This would read from UART and show on PORTD.
//If you send binary 01010011, PORTD will be equal to binary 01010011 and so on
Hope this helps.
Tahmid.
 
Top