|
|
View previous topic :: View next topic |
Author |
Message |
perthcom
Joined: 10 Jun 2005 Posts: 10
|
16F873 code has me stumped |
Posted: Fri Jun 10, 2005 12:19 pm |
|
|
Hi all
I've been trying to move working code from 16C57 to work on 16F873. I can't seem to get one output (PTT) to change unless i completely comment out the debounce_inputs() function. This function returns only any inputs that have changed since the last time it was called.
I've removed everthing else in the program leaving ony that function (which seems to work fine), and some test code that simply toggles PTT and play_rec outputs. The play_rec output toggles fine, but ptt is stuck high.
When I look at the C/ASM code i can see that it is BCF 7.3 which is correct (bit clear 7.3 which should take ptt low)
I just upgraded PCW in the last 2 hours thinking it had to be a bug, but its still the same. Here is the code:
Code: | #include <\program files\picc\devices\16F873.h>
#device adc=8
#use delay(clock=4000000,RESTART_WDT)
#fuses WDT,XT, PUT, NOPROTECT, BROWNOUT,noLVP, NOCPD, NOWRT, NODEBUG
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,restart_wdt)
#use FAST_IO(A)
#use FAST_IO(B)
#use FAST_IO(C)
#ZERO_RAM
#byte last_command = 20
//Status Port A
#byte status = 5
#bit batt_v = 5.0 //analog battery voltage
#bit command_data = 5.1 //command data to ic's
#bit clock = 5.2 //clock for IC's
#bit replay_data = 5.3 //reply back from ic's
//inputs Port B (except 6.7)
#byte inputs = 6
#bit start = 6.0 //input from paging decoder
#bit page_button = 6.1 //Local page button
#bit play_stop = 6.2 //play_stop button
#bit alarm = 6.3 //alarm button
#bit end_mess = 6.4 //End of Message flag from ISD chip
#bit overflow = 6.5 //Overflow flag from ISD chip
#bit spare_input= 6.6
#bit spare_output = 6.7
//#bit siren = 6.7
//outputs Port C
#byte control_port = 7 //set all controls output at once
#bit ce_isd = 7.0 //Low to enable chip
#bit powerdown = 7.1 //high to shut off chip
#bit play_rec = 7.2 //Low - record, High - Playback
#bit ptt = 7.3
#bit amp_en = 7.4
#bit message = 7.5
Debounce_inputs()
{
int input_buff,last_buff,debounce;
debounce = 20;
WHILE(debounce)
{
RESTART_WDT();
input_buff = inputs&0b00001111; //test inputs and mast off buttons
last_buff = input_buff^last_buff; //XOR test if buttons changed
IF (last_buff) debounce = 20; //buttons changed, reset debounce
last_buff = input_buff; //save switch positions
IF (!page_button) DELAY_MS(100); //for 2 sec. delay
DELAY_US(500); //gives 10ms debounce
--debounce;
}
last_buff = ~last_buff;
input_buff = ~input_buff; // flip active LOW to active HI
input_buff = last_command^input_buff;
input_buff = input_buff & last_buff;
last_command = last_buff;
RETURN(input_buff);
}
void main()
{
int cntr, command, temp;
int command1;
setup_adc_ports(RA0_ANALOG);
setup_adc(ADC_CLOCK_INTERNAL);
setup_spi(FALSE);
setup_counters(RTCC_INTERNAL,WDT_2304MS);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_ccp1(ccp_off);
setup_ccp2(ccp_off);
SET_TRIS_A(0b00001001);
SET_TRIS_B(0b01111111);
SET_TRIS_C(0b10000000);
control_port = 0b00000101; //set chip_en & play_rec to 1, rest = 0
play_rec = 1;
ce_ISD = 1; //disable ISD
powerdown = 1; //put chip in standby mode
DELAY_MS(500); //delay to stabilize circuit
printf("program started \n\r");
While (true)
{
play_rec = 1;
Delay_MS(200);
PTT = 0;
play_rec = 0;
DELAY_MS(400);
ptt = 1;
play_rec = 1;
RESTART_WDT();
command = DEBOUNCE_INPUTS();
printf("command=>%2x\n\r",command);
}
} |
any ideas? (ps, i don't write much code, so its not elegant)
thanks
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Jun 10, 2005 1:53 pm |
|
|
The problem is this line, right here:
Code: | #byte last_command = 20 |
20 is 0x14 in hex. That's the address of the SSPCON register.
What you've done is to assign a variable to a SFR register location.
So when you write to that variable, you're configuring Port C into
some SSP mode which does a peripheral override on the Port C i/o pins.
There's no reason to hardcode an address for a variable.
(At least, not normally).
I think maybe you're coming from another compiler where you had
to do this, but in CCS the compiler assigns the addresses automatically.
Just change it to:
Code: | int8 last_command = 20; |
(I'm assuming that you want to initialize it to a value of 20.) |
|
|
perthcom
Joined: 10 Jun 2005 Posts: 10
|
|
Posted: Fri Jun 10, 2005 2:10 pm |
|
|
hi
Thanks for the quick reply, I had just thought about that and changed it, walked back into my office while waiting for the programmer.. and read your message.
That was in there from the original 16C57 program, something about needing it that variable location defined before the function, but couldn't define it as a normal INT until after Main() so used the #byte .. it was written in about 1994 so very early CCS compiler.
Anyway.. works great now.. THANKS!!
|
|
|
|
|
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
|