sk40c to Uc00A

Discussion about projects that used PIC Microcontroller, Hardware Interface, Programming Algorithm and etc......

sk40c to Uc00A

Postby hafdzansauli » Sat Jun 09, 2012 3:08 pm

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--);
}

hafdzansauli
Greenhorn
 
Posts: 3
Joined: Sat Jun 09, 2012 2:47 pm

Re: sk40c to Uc00A

Postby robosang » Sun Jun 10, 2012 11:07 am

Try with actual wired connection first, look at the result and makesure the communication between your microcontroller to computer is correct, then only replace the wire with wireless.
robosang
Expert
 
Posts: 1239
Joined: Wed Jun 10, 2009 5:37 pm

Re: sk40c to Uc00A

Postby hafdzansauli » Sun Jun 10, 2012 11:37 am

ty robosang reply my problem...
I just try hardwire between pc n my mcu but it give unwanted symbol...
where is my problem in my program
hope anyone can help...
hafdzansauli
Greenhorn
 
Posts: 3
Joined: Sat Jun 09, 2012 2:47 pm

Re: sk40c to Uc00A

Postby robosang » Wed Jun 13, 2012 2:21 pm

Most likely is your baudrate 8-)
robosang
Expert
 
Posts: 1239
Joined: Wed Jun 10, 2009 5:37 pm

Re: sk40c to Uc00A

Postby hafdzansauli » Fri Jun 15, 2012 1:57 pm

ty roboson, my coding actually clash in ascII conversion when i differentiate ascII conversion between lcd and uart it fine now.
but in addition when i replace hardwire connected between UC00A and uart with RF recever and transmitter module its not continuous receiving data....
hafdzansauli
Greenhorn
 
Posts: 3
Joined: Sat Jun 09, 2012 2:47 pm

Re: sk40c to Uc00A

Postby yonghui » Fri Jun 15, 2012 4:09 pm

what is the RF module u r using?

if the low cost wireless please try to use low baudrate mayb 1200bps.
send 10 bytes of 0x00 1st before sending the actual data.


regards,
yh
thanks&regards,
yh
yonghui
Moderator
 
Posts: 732
Joined: Mon Sep 28, 2009 3:27 pm


Return to PIC Microcontroller

Who is online

Users browsing this forum: No registered users and 1 guest