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

Can't get to work the UART in PIC16f877

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



Joined: 23 Jun 2004
Posts: 3

View user's profile Send private message

Can't get to work the UART in PIC16f877
PostPosted: Tue Jul 13, 2004 8:55 am     Reply with quote

Hi guys

I used the pic16f873 for my project then I change the program to compile for my pic16f877a just the header but I can't get to work my uart on the pic16f877a. I sense the output and I read 0v all the time. what is happening.

My code is the following:

#include "E:\pictest\acelerometro877.h"
#include <stdio.h>
#include <string.h>

#define ADXL210_SCALING_FACTOR 10



void accelerometer_isr(void);
void accelerometer2_isr(void);
void accelerometer_init(signed int32 zerog, long ppg);
signed long accelerometer_read(void);


//global vars used to calculate G
long adxl_t1, adxl_t2,ad1,ad2;
long adxl2_t1, adxl2_t2,a2d1,a2d2;
short adxl_waiting_for_fall;
short adxl2_waiting_for_fall;


//global vars used calibrate
signed int32 adxl_zerog;
long adxl_ppg;
long ax1,ax2,a1x1,a1x2;
Union FTOB {
int8 b[2];
long lg;
};

void sendlong (union FTOB value) {
int count;
value.lg=ax1;
putc(value.b[1]);
putc(value.b[0]);

}

void sendlong1 (union FTOB value) {
int count;
value.lg=ax2;

putc(value.b[1]);
putc(value.b[0]);
}

void sendlong2 (union FTOB value) {
int count;
value.lg=a1x1;

putc(value.b[1]);
putc(value.b[0]);
}


void sendlong3 (union FTOB value) {
int count;
value.lg=a1x2;

putc(value.b[1]);
putc(value.b[0]);
}
#int_CCP1
//CCP1_isr()
void accelerometer_isr(void) {
static long adxl_last_rise;

if(adxl_waiting_for_fall) {
adxl_t1=CCP_1-adxl_last_rise;
setup_ccp1(CCP_CAPTURE_RE);
adxl_waiting_for_fall=FALSE;
} else {
adxl_t2=CCP_1-adxl_last_rise;
adxl_last_rise=CCP_1;
ad1=adxl_t1;
ad2=adxl_t2;

setup_ccp1(CCP_CAPTURE_FE);
adxl_waiting_for_fall=TRUE;
}
}

#int_CCP2
void accelerometer2_isr(void) {
static long adxl2_last_rise;

if(adxl2_waiting_for_fall) {
adxl2_t1=CCP_2-adxl2_last_rise;
setup_ccp2(CCP_CAPTURE_RE);
adxl2_waiting_for_fall=FALSE;
} else {
adxl2_t2=CCP_2-adxl2_last_rise;
adxl2_last_rise=CCP_2;
a2d1=adxl2_t1;
a2d2=adxl2_t2;

setup_ccp2(CCP_CAPTURE_FE);
adxl2_waiting_for_fall=TRUE;
}
}


void accelerometer_init(signed int32 zerog, long ppg) {
adxl_zerog=zerog;
adxl_ppg=ppg;

setup_ccp1(CCP_CAPTURE_RE);
adxl_waiting_for_fall=FALSE;
adxl2_waiting_for_fall=FALSE;
setup_timer_1(T1_INTERNAL);
setup_ccp2(CCP_CAPTURE_RE);
enable_interrupts(INT_CCP1);
enable_interrupts(INT_CCP2);
enable_interrupts(GLOBAL);


}

signed long accelerometer_read(void) { // Returns hundreths of a g
int32 value;
int8 value1;

ax1=ad1;
ax2=ad2;
a1x1=a2d1;
a1x2=a2d2;
value1 = read_adc();

putc(0xaa);
sendlong(ax1);
sendlong1(ax2);
sendlong2(a1x1);
sendlong3(a1x2);
putc(value1);

value = adxl_t1 ;

return(value);
}


void main()
{
int value;
signed int32 value1;
float value4;

port_b_pullups(TRUE);
setup_adc_ports(AN0);
setup_adc(ADC_CLOCK_INTERNAL);
setup_spi(FALSE);
setup_counters(RTCC_INTERNAL,RTCC_DIV_1);
setup_timer_2(T2_DISABLED,0,1);
accelerometer_init(50,4);

do {

set_adc_channel(0);

value1=accelerometer_read();
output_b(value);



} while (TRUE);
}


and the header:

#include <16F877A.h>
#device adc=8
#use delay(clock=20000000)
#fuses NOWDT,HS, PUT, NOPROTECT, NODEBUG, NOBROWNOUT, NOLVP, NOCPD, NOWRT
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)



Please give me suggestions

Thanks
rwyoung



Joined: 12 Nov 2003
Posts: 563
Location: Lawrence, KS USA

View user's profile Send private message Send e-mail

PostPosted: Tue Jul 13, 2004 9:53 am     Reply with quote

Code:
void main()
{
int value;
signed int32 value1;
float value4;

port_b_pullups(TRUE);
setup_adc_ports(AN0);
setup_adc(ADC_CLOCK_INTERNAL);
setup_spi(FALSE);
setup_counters(RTCC_INTERNAL,RTCC_DIV_1);
setup_timer_2(T2_DISABLED,0,1);
accelerometer_init(50,4);

do {

set_adc_channel(0);

value1=accelerometer_read();
output_b(value);



} while (TRUE);
}

You are reading your data into "value1" but writing out the variable "value". If "value" was not initialized and so may well be zero all the time.
_________________
Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month!
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