hi i'm beginner in pic program using C language, i got a problem with my project that i work for. my sk40c receive input from port AN0 and data from that i want transmit using RF module wireless through UART (TX port), at receiver i use UC00A (usb to UART converter), supposedly when i connect that UC00A to computer i can receive the value of input at AN0. help me on program pls
- CODE: SELECT_ALL_CODE
#include<pic.h>
__CONFIG (0x3F32);
#define CHANNEL0 0b10000001
void read_adc(void);
void delay(unsigned short i);
void uart_transmit(result);
unsigned short read_temp(void);
unsigned short result;
unsigned short temp;
void main(void)
{
ADRESH=0;
ADRESL=0;
ADCON1=0b11000000;
TRISA=0b11111111;
TRISB=0b00000000;
TRISD=0b00000000;
PORTB=0;
PORTD=0;
unsigned char dummy = 0;
BRG16 = 0;
SYNC = 0;
TX9 = 0;
RX9 = 0;
BRGH = 1; // Select high speed baud rate.
SPBRG = 129; // Configure the baud rate.
SPEN = 1; // Enable serial port.
CREN = 1; // Enable reception.
TXEN = 1; // Enable transmission.
dummy = RCREG; // dummy read, to clear the receive buffer
dummy = RCREG;
while(1)
{
ADCON0=CHANNEL0;
read_adc();
temp=read_temp();
delay(20000);
uart_send(result);
}
}
void read_adc(void)
{
unsigned short i;
unsigned long result_temp=0;
for(i=20000;i>0;i-=1)
{
ADGO = 1;
while(ADGO==1);
result=ADRESH;
result=result<<8;
result=result|ADRESL;
result_temp+=result;
}
result = result_temp/20000;
}
unsigned short read_temp(void)
{
unsigned short temp;
temp=result;
return temp;
}
void uart_transmit(result)
{
while (TXIF == 0);
TXREG = result;
}
void uart_send(result)
{
while (result != '\0')
{
uart_transmit(result);
result++;
}
}
void delay(unsigned short i)
{
for(;i>0;i--);
}