View previous topic :: View next topic |
Author |
Message |
abc Guest
|
Need help on RF out |
Posted: Thu Nov 01, 2007 10:26 pm |
|
|
Code: | #include <12F683.h>
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES INTRC_IO //Internal RC Osc, no CLKOUT
#FUSES NOCPD //No EE protection
#FUSES PROTECT //Code protected from reads
#FUSES NOMCLR //Master Clear pin used for I/O
#FUSES NOPUT //No Power Up Timer
#FUSES NOBROWNOUT //Reset when brownout detected
#FUSES NOIESO //Internal External Switch Over mode disabled
//#FUSES FCMEN //Fail-safe clock monitor enabled
#use delay(clock=4000000,RESTART_WDT)
#ZERO_RAM
#define RFOUT PIN_A0
unsigned int8 ii=0;
INT1 k=0;
struct {
unsigned int8 aa;
unsigned int8 bb;
unsigned int8 cc;
unsigned int8 dd;} cmd;
void RF_send(void);
void main()
{
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_OFF);
setup_timer_0(RTCC_INTERNAL);
//setup_wdt(WDT_DIV_32768);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC);
setup_vref(FALSE);
setup_oscillator(OSC_4MHZ);
cmd.aa = 0x22;
cmd.bb = 0x33;
cmd.cc = 0x44;
cmd.dd = 0x55;
while(1)
{
delay_ms(3);
RF_send();
}
}
void RF_send()
{
for(ii=1;ii<=32;++ii) {
if(shift_left(&cmd,4,1))//1
{
output_high(RFOUT);
delay_us(300);
output_low(RFOUT);
delay_us(600);
}
else//0
{
output_high(RFOUT);
delay_us(600);
output_low(RFOUT);
delay_us(300);
}
}
}
|
if(shift_left(&cmd,4,1))
what wrong?
i always got 0xffffffff on receiver site...
it should be:
cmd.aa = 0x22;
cmd.bb = 0x33;
cmd.cc = 0x44;
cmd.dd = 0x55;
i need help... |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Nov 01, 2007 11:35 pm |
|
|
Post your compiler version. |
|
|
abc Guest
|
|
Posted: Fri Nov 02, 2007 12:21 am |
|
|
compiler version=pcwh 3.249 |
|
|
Guest
|
|
Posted: Fri Nov 02, 2007 12:23 am |
|
|
if(shift_left(&cmd,4,1))
why this always is 1??
any suggestion? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Nov 02, 2007 1:32 am |
|
|
I installed vs. 3.249 and added the lines shown below in bold to your
program. I then compiled the program and ran it in the MPLAB
simulator. I put a breakpoint on the delay_cycles(1) line. I opened
a Watch Window and watched the 'c' variable. I pressed the F9 key
repeatedly to step through the for() loop. The 'c' variable changed in
this pattern for the first 8 bits:
That's correct.
I also looked at the CCS start-up code that the compiler inserts at
the beginning of main(). It turns off the comparators correctly and
it sets all analog pins to be digital i/o. It also sets up the oscillator
correctly for internal operation. The config bits also look correct.
So, I think you should look at the external connections to your RF
transmitter and also look at the transmitter.
Quote: | void RF_send()
{
int c;
for(ii=1;ii<=32;++ii) {
if(shift_left(&cmd,4,1))//1
{
c = 1;
output_high(RFOUT);
delay_us(300);
output_low(RFOUT);
delay_us(600);
}
else//0
{
c = 0;
output_high(RFOUT);
delay_us(600);
output_low(RFOUT);
delay_us(300);
}
delay_cycles(1); // Put a Breakpoint here.
}
} |
|
|
|
abc Guest
|
|
Posted: Fri Nov 02, 2007 2:57 am |
|
|
thanks PCM programmer,
i have tested the rf out using osiloscope,it always :
when
if(shift_left(&cmd,4,1))//1
the rf out always is:
output_high(RFOUT);
delay_us(300);
output_low(RFOUT);
delay_us(600);
when
if(shift_left(&cmd,4,0))//0
the output always is:
output_high(RFOUT);
delay_us(600);
output_low(RFOUT);
delay_us(300);
i will test again,
i dont know why it cant point to the address:
cmd.aa = 0x22;
cmd.bb = 0x33;
cmd.cc = 0x44;
cmd.dd = 0x55;
...... |
|
|
abc Guest
|
|
Posted: Fri Nov 02, 2007 3:19 am |
|
|
hi, i found the problem, it only work correctlly at first loop, second and so on loop is wrong, how to solve this problem?
while(1)
{
delay_ms(3);
RF_send();
}
first loop ok only.... |
|
|
Wayne_
Joined: 10 Oct 2007 Posts: 681
|
|
Posted: Fri Nov 02, 2007 6:16 am |
|
|
It is because you are shifting in to your 4 byte data array a 1 for each bit you shift out.
if(shift_left(&cmd,4,1))//1
To fix it you need to either reset you data for each iteration of the loop or shift back in the value you shifted out! |
|
|
|