CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

PIC RS232 Transmission

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
PIC2OLED
Guest







PIC RS232 Transmission
PostPosted: Wed Sep 09, 2009 10:08 am     Reply with quote

Hi I am using the pic16f818 and I am using the A/D converter to generate an 8bit number. I want to transmit that number via rs232. I am sure I connected everything fine, but somehow the PIC is sending 1s all the time. Sad
And I have no clue at all what the problem might be, because before I send it I flash LEDs such that they represent the value and they flash properly i.e not all are lit up Shocked

Here is my code:
Code:

#include <16F818.h>
#DEVICE ADC=8;
#use delay(clock=20000000)   
#use rs232(BAUD=9600, XMIT=PIN_B2, RCV=PIN_B1, BITS=8, PARITY=N)
#fuses HS, NOWDT, NOBROWNOUT, NOPUT

unsigned int8 value;                                 //declare variable value which is an 8 bit number
void main(void)
{
   SET_TRIS_B(0b00001010);                        //0 means output, 1 means input; output pins B4 to B7 and B2
   SET_TRIS_A(0b00100011);                        //0 means output, 1 means input;
   
   output_bit(Pin_B4, 1);                        //just flashing LEDS at beginning to make sure it is all fine
   output_bit(Pin_B5, 1);
   output_bit(Pin_B6, 1);
   output_bit(Pin_B7, 1);
   output_bit(Pin_A2, 1);
   output_bit(Pin_A3, 1);
   output_bit(Pin_A4, 1);
   output_bit(Pin_B0, 1);
   delay_ms(1000);
   output_bit(Pin_B4, 0);
   output_bit(Pin_B5, 0);
   output_bit(Pin_B6, 0);
   output_bit(Pin_B7, 0);
   output_bit(Pin_A2, 0);
   output_bit(Pin_A3, 0);
   output_bit(Pin_A4, 0);
   output_bit(Pin_B0, 0);
   delay_ms(1000);
   output_bit(Pin_B4, 1);
   output_bit(Pin_B5, 1);
   output_bit(Pin_B6, 1);
   output_bit(Pin_B7, 1);
   output_bit(Pin_A2, 1);
   output_bit(Pin_A3, 1);
   output_bit(Pin_A4, 1);
   output_bit(Pin_B0, 1);
   
   printf("U");                                 //Send a U to the uOLED for baud detect
   
   SETUP_ADC_PORTS(AN0);               SETUP_ADC(ADC_CLOCK_INTERNAL);             
   
   delay_ms(10000);
   
   do{
      
      SET_ADC_CHANNEL(0);
      delay_us(50);
      value=READ_ADC(ADC_START_AND_READ);           //start converting
      delay_us(50);
      
      putc(value);                           //send value
      
      //flash LEDs  such that they represent value
      output_bit(Pin_B4, bit_test(value,0));
      output_bit(Pin_B5, bit_test(value,1));
      output_bit(Pin_B6, bit_test(value,2));
      output_bit(Pin_B7, bit_test(value,3));
      output_bit(Pin_A2, bit_test(value,3));
      output_bit(Pin_A3, bit_test(value,5));
      output_bit(Pin_A4, bit_test(value,6));
      output_bit(Pin_B0, bit_test(value,7));


      
   } while (TRUE);
   
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Sep 09, 2009 12:04 pm     Reply with quote

Make a simple program that only reads the ADC and sends the result
to a terminal window on your PC. Examples:

This program sends the ADC value in Hexadecimal format to the PC:
http://www.ccsinfo.com/forum/viewtopic.php?t=34386&start=1

This program converts the ADC value to a voltage and sends it to the PC:
http://www.ccsinfo.com/forum/viewtopic.php?t=32168&start=1
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group