glenjoy
Banned
![Advanced Member level 3](/styles/images/ranks/glevel3.gif)
- 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:
Thanks.
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.