Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Help me in my CCS SourceCode

Status
Not open for further replies.

glenjoy

Banned
Advanced Member level 3
Joined
Jan 1, 2004
Messages
962
Helped
72
Reputation
146
Reaction score
20
Trophy points
1,298
Location
Philippines
Activity points
0
Hi,

Can someone help me verify my code, sometmes this code resets and it creates warnings when I compile it with Microchip MPLAB IDE but no warnings in CCS.

Here is the code:

Code:
#include "C:\Documents and Settings\COA\My Documents\PIC Projects\Line_PIC\Line_PIC.h"

void Start();
void Run();
void TurnRight();
void TurnLeft();
void Forward();
void Reverse(char speed);



unsigned char high,low,flag,time;

#byte A_PORT=0x05
#byte B_PORT=0x06


void main()
{

   port_b_pullups(TRUE);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);

   SET_TRIS_A( 0xFF );
   SET_TRIS_B( 0x40 );

   A_PORT = 0xFF;
   B_PORT = 0x43;

   high = 80;
   low = 30;
   flag = 0;
   time = 100;
//   Start();
   while(1)
         {
         A_PORT |= 0x0F;
         Run();
         }

}

Start()
{
   char exit,key;
   exit = 1;
      while(exit)
      {
      key = B_PORT;
      if((key & 0x40) == 0)
      exit = 0;
      }
}


Run()
{
   char sensors;
   sensors = (A_PORT &= 0x0F);

   if((sensors & 0x01) == 0) // Turn Right
   {
   TurnRight();
   flag = 1;
   }

   else if((sensors & 0x08) == 0) // Turn Left
   {
   TurnLeft();
   flag = 2;
   }

   else if(sensors == 0x09) // Forward High
   {
   Forward();
   flag = 0;
   }

   else if(((sensors == 0x0B) || (sensors == 0x0D)) && (flag == 0))  // Forward Low
   {
   Forward();
   }
}

Forward()
{
   B_PORT = 0x67;

   delay_ms(time);
}

TurnRight()
{
   B_PORT = 0x6B;

   delay_ms(time);
}

TurnLeft()
{
   B_PORT = 0x57;

   delay_ms(time);
}

Reverse(char speed)
{
   B_PORT = 0x5B;

   delay_ms(time);
}

Thanks.
 

Hi,

What are those warnings?
What is the reset reason?
(You should check it immediately after boot up,
it can caused by stack owerflow, user, etc.)
(example: RCON Register on a 18F8x20)

regards
Zed
 

Hi glenjoy,

1)
You didn't post the full header, it is important to see how do you define some pre-processor directives.
We doesn´t know wich microcontroller, oscillator type and Configuration Word are you using.

2)
#byte A_PORT=0x05
#byte B_PORT=0x06
Are Ok. Using #byte a C variable is created and mapped to hardware registers.

humber555
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top