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 support@ccsinfo.com

RC5 [Manchester] Decoding ....Does this Work ??

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







RC5 [Manchester] Decoding ....Does this Work ??
PostPosted: Tue Jan 14, 2003 8:39 am     Reply with quote

#include <16f876.h>
#Device ICD=TRUE
#use delay(clock=4000000)
#bit T0IF=0xB.2
#bit INTF=0xB.1
#use rs232(BAUD=9600, xmit=pin_c6, rcv=pin_c7)

int newbit=0,ready=0,offset=1,i=0;
long count=0,code=0,abtast=75;

void main()
{
set_tris_A(0xFF);
set_tris_B(0xFF);
set_tris_C(0x00);
enable_interrupts(global); enable_interrupts(int_ext); ext_int_edge(H_TO_L);
while(1) {
while(ready==1)
{
if(i<14)
{
count=get_timer0();
if(count>=abtast)
{
newbit=input(Pin_A0);
code=code|newbit;
code<<=code;
abtast=abtast+111;
printf("\%c",code);
}
i++;
ready=0;
}
}
}
}

#int_ext
isr() {
disable_interrupts(int_ext); setup_timer_0(RTCC_DIV_16|RTCC_Internal);
set_timer0(0);
ready=1;
}
___________________________
This message was ported from CCS's old forum
Original Post ID: 10682
Hans Wedemeyer
Guest







Re: RC5 [Manchester] Decoding ....Does this Work ??
PostPosted: Tue Jan 14, 2003 9:17 am     Reply with quote

no...!
Not sure about your actual code, but these items are critical
You did not initialize Timer 0.
Do this BEFORE you release the global interrupt.

void main()
{
set_tris_A(0xFF);
set_tris_B(0xFF);
set_tris_C(0x00);

setup_timer_0(RTCC_DIV_16|RTCC_Internal);
ext_int_edge(H_TO_L);
enable_interrupts(int_ext);

enable_interrupts(global); // let it rip

while(1)
{
// your code here
}
}

No need to stop interrupts in int_ext just set timer0() and the flag
#int_ext
isr() {
{
set_timer0(0);
ready=1;
}
I'm not sure what your need is when setting Timer0 to zero,
I expect you are trying to measure something...If the external input is what's being measured then I don;t see how it will work !

If you Get_Timer0() before resetting it, you will be able to measure the time between the last interrupt and the current interrupt. Assuming Timer0 does not overflow. !

int DeltaTime=0; // some global var.

#int_ext
isr() {
{
DeltaTime = Get_Timer0(); / time since last event
set_timer0(0);// start measuring next event
ready=1;
}
___________________________
This message was ported from CCS's old forum
Original Post ID: 10685
chriss2000
Guest







Re: RC5 [Manchester] Decoding ....Does this Work ??
PostPosted: Wed Jan 15, 2003 2:59 pm     Reply with quote

#include <16f876.h>
#Device ICD=TRUE
#use delay(clock=4000000)
#bit T0IF=0xB.2
#bit INTF=0xB.1
#use rs232(BAUD=9600, xmit=pin_c6, rcv=pin_c7)

int newbit=0,flag=0,offset=1,i=0;
long count=0,code=0,abtast=75;

#int_ext //allow ext interrupt
isr() //Interrupt Service Routine
{
disable_interrupts(int_ext); //disable interrupt on Pin B0 [until the next signal
set_timer0(0); //Set Timer 0 to zero
flag=1; //Set Interruptflag to 1
}

void main()
{
set_tris_A(0xFF);
set_tris_B(0xFF);
set_tris_C(0x00);
setup_timer_0(RTCC_DIV_16|RTCC_Internal); //Timer 0 Setup, counts up with 62,5kHz
//Teilung: When the counter has the value 1, 16us have left

enable_interrupts(int_ext); //Allow ext Interrupt on Rb0
enable_interrupts(global); //Allow Global Interrupt
ext_int_edge(H_TO_L); //Wait for falling edge--> then jump to Interrupt Service Routine
while(1) //As long as True -->Make Main
{
while(flag=1)
{
if(i<14) //14 Bit Code-->scan 14 times
{
count=get_timer0(); //Get counter time
if(count>=abtast) //If counter time is greater than the value were i want to scan my signal-->scan the Pin A0
{
newbit=input(Pin_A0); //get the bit value of Pin A0
code=code|newbit;
code<<1; //Shift the input values in my integer
abtast=abtast+111; //count up my scan value

}
i++;
}

delay_ms(80); //80ms delay to wait for the beginning of the next signal
enable_interrupts(int_ext); //allow ext Interrupt on Pin B0
flag=0; //Set The Interrupt Flag to Zero to get out of the cycle
abtast=75; //The Timer Value 75 is the same as 1,2 ms and i need that time to scan my bit in the 3/4 bit size
i=0;
}
}
}
___________________________
This message was ported from CCS's old forum
Original Post ID: 10728
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