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

Need help on RF out

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







Need help on RF out
PostPosted: Thu Nov 01, 2007 10:26 pm     Reply with quote

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... Crying or Very sad

it should be:
cmd.aa = 0x22;
cmd.bb = 0x33;
cmd.cc = 0x44;
cmd.dd = 0x55;

i need help... Crying or Very sad
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Nov 01, 2007 11:35 pm     Reply with quote

Post your compiler version.
abc
Guest







PostPosted: Fri Nov 02, 2007 12:21 am     Reply with quote

compiler version=pcwh 3.249
Guest








PostPosted: Fri Nov 02, 2007 12:23 am     Reply with quote

if(shift_left(&cmd,4,1))
why this always is 1??

Crying or Very sad

any suggestion?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Nov 02, 2007 1:32 am     Reply with quote

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:
Quote:
0 1 0 1 0 1 0 1

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







PostPosted: Fri Nov 02, 2007 2:57 am     Reply with quote

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







PostPosted: Fri Nov 02, 2007 3:19 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Nov 02, 2007 6:16 am     Reply with quote

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!
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