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

16f877, ccs, adc, serial communication

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







16f877, ccs, adc, serial communication
PostPosted: Wed Sep 13, 2006 12:55 am     Reply with quote

hi,

i want to read two analog input and after converting them to dijital, i will sent them to serial port one by one. i have writen the following code but something is wrong, do you have any idea?

//////////////////////////////////////////
// ADC and Serial Communication //
// 2 channel Analog Input //
// 1 channel serial digital RS232 output//
// Ali Özgür Argunşah //
// argunsah@su.sabanciuniv.edu //
//////////////////////////////////////////

#include <16F877.h>
#fuses XT,NOWDT,NOPROTECT,NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7) // Jumpers: 8 to 11, 7 to 12

void main() {

long int input1;

setup_adc(ADC_CLOCK_INTERNAL);
setup_adc_ports(ALL_ANALOG);

//delay_ms(2000);

do {
set_adc_channel(0);
delay_cycles(60);
input1 = read_adc();
putc(input1);

set_adc_channel(1);
delay_cycles(60);
input1 = read_adc();
putc(input1);

} while(TRUE);

}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Sep 13, 2006 1:11 am     Reply with quote

What do you mean by "something is wrong" ?

Tell us what you expect to see, and what you are actually seeing.
creativity
Guest







PostPosted: Wed Sep 13, 2006 1:43 am     Reply with quote

I expect to read the serial output of 16f877 with a matlab code given below. I gave a sinus signal to one input and zero to the second one. i expect to see a sinus with some zeros inside (one sin signal and one zero, and so on) but i only see some random signal. as you see more than "something" is wrong Smile

s1 = serial('COM3', 'BaudRate', 9600,'Databits',10);

fopen(s1);

eye=zeros(512*2,1);

for i=0:1
eye(i*512+1:i*512+512) = fread(s1)
% plot(eye)
end

plot(eye);
fclose(s1);
Ttelmah
Guest







PostPosted: Wed Sep 13, 2006 2:46 am     Reply with quote

How many Databits should there be?...

Best Wishes
creativity
Guest







PostPosted: Wed Sep 13, 2006 3:57 am     Reply with quote

i changed code to the code below and it works:

//////////////////////////////////////////
// ADC and Serial Communication //
// 2 channel Analog Input //
// 1 channel serial digital RS232 output//
// Ali Özgür Argunşah //
// argunsah@su.sabanciuniv.edu //
//////////////////////////////////////////

#include <16F877.h>
#device adc=8
#fuses XT,NOWDT,NOPROTECT,NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, parity=N, bits=8) // Jumpers: 8 to 11, 7 to 12

void main() {

long int input1;

setup_adc(ADC_CLOCK_INTERNAL);
setup_adc_ports(ALL_ANALOG);

//delay_ms(2000);

do {
set_adc_channel(0);
delay_cycles(60);
input1 = read_adc();
putc(input1);

set_adc_channel(1);
delay_cycles(60);
input1 = read_adc();
putc(input1);

} while(TRUE);

}

thank you for all replies.
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