PIC16F88 wireless serial comms with USART

This is a discussion on PIC16F88 wireless serial comms with USART within the C Programming forums, part of the General Programming Boards category; Hi, I am relatively new to C programming and completely new to USART operation. I am trying to measure an ...

  1. #1
    Registered User
    Join Date
    May 2011
    Posts
    2

    Cool PIC16F88 wireless serial comms with USART

    Hi,
    I am relatively new to C programming and completely new to USART operation.
    I am trying to measure an analogue input in one PIC then allocate these values into 7 different classes depending on their value. I then want to assign an identifier to each class, in this case, the 0, 1, 2, 3 and so on. With these numbers, I want to send them to another PIC connected via a RF 433mhz wireless module. When the data is received on the other side, this will correspond to a series of LEDS which should illuminate when the ADC input changes.

    I have a start on the code using my existing code that worked without the USART wireless included and using the PIC16F88 datasheet.

    Any help as to why this isnt working would be much appreciated.

    Here is the transmitter code:
    Code:
    //PIC 16F88 microcontroller 
    
    #include <pic.h>
    #include "delay.c"
    #include "delay.h"
      
    __CONFIG(WDTDIS & INTIO & PWRTEN & MCLRDIS & UNPROTECT & BORDIS); 
    
    
    main()
    
    {
       int ADCresult= 0;
    
       CMCON = 7;                       //Turn off comparators
       ANSEL = 0b00000100;        //Pin 11- RA2/AN2 as analogue input.
       TRISA= 0b00000100;         //PortA as output except RA2 as input
       TRISB = 0;                          //PortB as output
       //OSCCON= 0b01111110;   //This is to set the internal OSC to 8 Mhz
    
       ADCON0= 0b00001001;    //Result left justified format, voltage reference= VDD, 
                                                   //AN2= analogue input, initiates ADC and waiting to start conversion.
       ADCON1= 0b00010000;     //For 4 Mhz, 8Tosc= 2 uS, which > 1.6 uS, the minimum requirement. 
    
    
    SPBRG = 25; 
    BRGH = 1; // speed USART, high speed - baudrate more acurate 
    
    SYNC = 0; // async mode 
    SPEN = 1; // serial port enable bit 
    
    // transmit 
    TXIE = 0; // initialize transmit 
    TX9 = 0; // disabled 9 bit transmission 
    TXEN = 0; 
    TXEN = 1; // transmit enable bit 
    TXREG =0;
    
    
    while(1)
       {
         DelayUs(50);                  //Wait minimum sample time.
         GODONE = 1;                //Start conversion.
         while(GODONE== 1);   //Wait until conversion is done.
         ADCresult= ADRESH;    //Transfer from ADRESH to ADCresult. 
        
       
    	if(ADCresult<= 76){
    TXREG= 0x0; 
    }
    	else if(ADCresult<= 102){
    TXREG= 0x1;
    }
    	else if(ADCresult<= 128){
    TXREG= 0x2;
    }
    	else if(ADCresult<= 153){
    TXREG= 0x3;
    }
    	else if(ADCresult<= 179){
    TXREG= 0x4;
    }
    	else if(ADCresult<= 204){
    TXREG= 0x5;
    }
    	else if(ADCresult<= 255){
    TXREG= 0x6;
    }
    }
    }
    and here is the receiver code:
    Code:
    //PIC 16F88 microcontroller 
    
    #include <pic.h>
    #include "delay.c"
    #include "delay.h"
      
    __CONFIG(WDTDIS & INTIO & PWRTEN & MCLRDIS & UNPROTECT & BORDIS); 
    
    const char display_portb[]= {0b00000001, 0b00000010, 0b00001000, 0b00010000,
                                                    0b01000000, 0b10000000};
    
    main()
    {
    
    SPBRG = 25; 
    BRGH = 1; // speed USART, high speed - baudrate more acurate 
    
    SYNC = 0; // async mode 
    SPEN = 1; // serial port enable bit 
    
    
    // receive 
    CREN = 1; // enable continues receive 
    RCIE = 0; // interrupt cleared 
    RX9 = 0; // disabled 9 bit reception 
    ADDEN = 0; // geen adress detectie (9e bit) 
    RCREG = 0;
    
    while(1)
    {
    
     	if(RCREG=0x0) 
    		{
    			PORTB= 0;
    		}
            else if(RCREG=0x1) PORTB= display_portb[0];
             else if(RCREG=0x2) PORTB= display_portb[1];
              else if(RCREG=0x3) PORTB= display_portb[2];
               else if(RCREG=0x4) PORTB= display_portb[3];
                else if(RCREG=0x5) PORTB= display_portb[4];
                  else if(RCREG=0x6) PORTB= display_portb[5];
    
    }
    }
    Thanks
    C.Fry

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Without even trying to follow the logic: "if(RCREG=0x1)" all these should be ==.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Parent/Child comms homework
    By csgirl in forum C Programming
    Replies: 7
    Last Post: 05-15-2010, 03:40 PM
  2. Wireless N
    By laserlight in forum Tech Board
    Replies: 11
    Last Post: 12-02-2008, 03:35 AM
  3. wireless
    By Wraithan in forum Tech Board
    Replies: 1
    Last Post: 02-15-2006, 06:04 PM
  4. PIC16F876 's USART
    By Tombear in forum C Programming
    Replies: 4
    Last Post: 04-19-2002, 09:35 AM
  5. HELP... LabVIEW Fluke 45 Serial Comms VI
    By studentsaj in forum Windows Programming
    Replies: 0
    Last Post: 03-08-2002, 11:17 AM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21