PIC16f690 uart to LED

Discussion in 'Embedded Systems and Microcontrollers' started by adulfo, Feb 21, 2010.

  1. adulfo

    Thread Starter New Member

    Feb 10, 2010
    6
    0
    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
     
  2. Tahmid

    Active Member

    Jul 2, 2008
    344
    25
    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.
     
  3. adulfo

    Thread Starter New Member

    Feb 10, 2010
    6
    0
    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.
     
  4. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    Can you post your code, and your schematic?
     
  5. Tahmid

    Active Member

    Jul 2, 2008
    344
    25
    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:
    Code ( (Unknown Language)):
    1.    int R1, R2;
    2.     USART_Init(9600); //9600bps
    3.     R1 = ADC_Read(0)>>2; //Read CH0 (8-bit)
    4.     R2 = ADC_Read(2)>>2; //Read CH1 (8-bit)
    5.     USART_Write(R1); //Send reading1
    6.     delay_ms(1); //Wait for 1ms
    7.     USART_Write(R2); //Send reading2
    8. //This would be the reading from ADC and sending to PC part.
    9. //This would just send the readings, nothing else
    10. //This code is for mikroC v8.2, I don't know about other versions
    Code ( (Unknown Language)):
    1.    unsigned char R3;
    2.    if (USART_Data_Ready()){
    3.       R3 = USART_Read();
    4.       PORTD = R3;
    5.    }
    6. //This would read from UART and show on PORTD.
    7. //If you send binary 01010011, PORTD will be equal to binary 01010011 and so on
    Hope this helps.
    Tahmid.
     
  6. adulfo

    Thread Starter New Member

    Feb 10, 2010
    6
    0
    Thank you so much Tahmid. I'll just post if something go wrong along the way.
     
Loading...