Jules_Theone
Member
I'm currently learning how to program in C, with limited experience in assembly and BASIC. I've read some stuff on syntax etc and uploaded example code to my PK1, which works fine, but it doesn't make much sense to me. So I thought to understand the programming better, write the program from scratch to simply flash an led and go from there, ultimately to make a PIC based CAN to serial converter.
It appears to compile and program without errors, which suggests there is something wrong with the code. The led between RA4 and RA5 is half on. But I can't see the problem(s) comparing this with example code from others. Also is there a list of good practice techniques or simply cut and paste code from others (without really understanding?)
The PIC is a 16F688 ( so I can get the RS232 part working later) in MPLAB 8.5 with Hi-Tech compiler
It appears to compile and program without errors, which suggests there is something wrong with the code. The led between RA4 and RA5 is half on. But I can't see the problem(s) comparing this with example code from others. Also is there a list of good practice techniques or simply cut and paste code from others (without really understanding?)
Code:
/*
*/
#include <pic.h>
__CONFIG(FCMDIS & IESODIS & BORDIS & UNPROTECT & UNPROTECT & MCLREN & PWRTDIS & WDTDIS & INTCLK);
//Define Variables
int i,j;
void init_device(void)
{
PORTA = 0x00; //Clear PORTA
CMCON0 = 0x07; //Comparators off. Digital I/O Enable
ANSEL = 0x00; //ADC Disable
TRISA = 0x0F; //Set TRISA as Outputs
INTCON = 0; //Interrupts Disabled
}
void main(void)
{
init_device();
while(1) //Loop Forever
{
for (i = 0; i < 200; i++) // Simple Delay
for (j = 0; j < 150; j++);
RA4 = 1; //D0 On
for (i = 0; i < 200; i++) // Simple Delay
for (j = 0; j < 150; j++);
RA4 = 0; //D0 Off
}
}
The PIC is a 16F688 ( so I can get the RS232 part working later) in MPLAB 8.5 with Hi-Tech compiler
Last edited: