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

Need help rewriting a BS2 subroutine for PIC C

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








Need help rewriting a BS2 subroutine for PIC C
PostPosted: Sun Nov 13, 2005 2:58 pm     Reply with quote

Hi,

I'm just starting to learn C, and I trying to do a project using an Ultralink WWVB receiver. I have some code for the Basic Stamp 2 that I'm trying to re-write in CCS C. The code I've translated seems to almost work, but not quite and I'm having trouble getting the functionality to match. Can someone take a look?

Basic Stamp Code:
Code:

DIAGNOSTIC_MODE:
SEROUT   TXpin,BAUD,[$02]      'execute diagnotic mode
TEMP_REG = 0            'counting register is reset to zero
Read_Mode:
DEBUG   "COUNT = ",DEC TEMP_REG,CR   'display count
SERIN   RXpin,BAUD,2000,no_response2,[DAT1]   
IF   DAT1 <> %00000011 THEN Increase_Count   'see if diagnostic mode returns a '03'hex
TEMP_REG = 0            'if a '03'hex is returned then reset counter
HIGH   DatBad            'light no signal lock LED
LOW   DatGood            'extinguish signal lock LED
GOTO   Read_Mode            'continue checking
Increase_Count:
TEMP_REG = TEMP_REG + 1         'increment count of "good" responses
If TEMP_REG < 60 THEN Read_Mode   'after a minute of "good" responses    
HIGH   DatGood            'consider the receiver locked
LOW   DatBad            'set LEDs to display data as valid
RETURN
no_response2:
GOTO DIAGNOSTIC_MODE
END:


My code:

Code:


Void Diagnostic_Mode()
{
        Byte Temp_Reg;          //counting/working register
        Byte Data;              //data received in diagnostic mode
       
        Temp_Reg = 0;           // counting register is reset to zero
       
        fputc(0x02, Clock);           // '02' hex puts decoder in diagnotic mode
 
        do      //reading mode
        {
                do
                {
                        Data=fgetc(Clock);
                        printf(lcd_putc,"\fData = %u\n",Data);
                        Output_high(DataBad);                   //light no signal lock LED
                        Output_low(DataGood);                   //extinguish signal lock LED
                        Temp_Reg = 0;
                }
                while (Data != 0b00000011);

                Temp_Reg++;
                lcd_putc(" \fEnd Mode\n");
                Output_high(DataGood);                  'consider the receiver locked
                Output_low(DataBad);                    'set LEDs to display data as valid


        }
        while (Temp_Reg < 60);
        return;




Argh!! I don't seem to get how to make the code work the same way given the lack of "Go to" in C........

Oh, BTW, once the module is put in "diagnostic mode" it send a status byte each second. The byte can be 0, 1, 2 or 3. If it's 3 the reply is not "good", everything else indicates a "good" response. One minute of "good" is supposed to signify that the clock is locked on the time signal.


Thanks!

Bob
asmallri



Joined: 12 Aug 2004
Posts: 1634
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Sun Nov 13, 2005 5:21 pm     Reply with quote

Code:
Void Diagnostic_Mode()
{
   Byte Data;                 //data received in diagnostic mode
   Byte Temp_Reg = 0;     //counting/working register  is reset to zero     
       
   fputc(0x02, Clock);      // '02' hex puts decoder in diagnotic mode
 
   while(1)      //reading mode
   {
      Data=fgetc(Clock);
      if (Data != 0b00000011)
      {
         Temp_Reg++;
         if (Temp_Reg >= 60)
         {
            lcd_putc(" \fEnd Mode\n");
            Output_high(DataGood);           //consider the receiver locked
            Output_low(DataBad);              // set LEDs to display data as valid
            return;
         }
      }
      else
      {
         Temp_Reg = 0;
         Output_high(DataBad);                   //light no signal lock LED
         Output_low(DataGood);                   //extinguish signal lock LED         
         printf(lcd_putc,"\fData = %u\n",Data);
      }
   }
}

_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
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