Re: Problem with HI Tech
There are quite a few differences between the PIC16 and PIC18 architectures. All the #defines for registers, bits and configuration bits can be found in the appropriate header file located in the "include" directory, in this case pic16f877a.h.
Example Path to "include" directory:
C:\Program Files\HI-TECH Software\PICC\9.81\include
Also, especially when learning the PIC architecture, it is more advantageous to use this form:
Code:
__CONFIG(CP_OFF & CPD_OFF & BOREN_OFF & WDTE_OFF & PWRTE_ON & FOSC_HS & FCMEN_OFF & IESO_OFF); //Only an example not for the PIC16F877A
then this form:
The appropriate configuration bit #defines are located at the top of your device's header file, in this case pic16f877a.h.
Using the former example, allows you to turn on and off features without memorizing the configuration register's bit pattern.
You would most likely benefit from studying the best tutorials I've come across on the NET to date:
**broken link removed**
They are very professionally done, cover both the baseline and midrange PICs, using both MPASM Assembler and Hi-Tech C. Each lesson is in PDF form along with downloadable source code. The midrange C tutorials start off with using the 12F629, but soon move on to the 16F series.
---------- Post added at 23:43 ---------- Previous post was at 23:15 ----------
this time the problem is while using timer 0..... The book which I am following teaches to use pic18 but if I try programming pic16 I face problems. This time I used the following code:
#include<pic.h>
#include<htc.h>
__CONFIG(0x3F32);
#define _XTAL_FREQ 4000000
void main(void)
{
TRISAbits.TRISA4 = 1;
TRISB = 0;
T0CON = 0x78;
while(1)
{
do{
T0CONbits.TMR0ON = 1;
PORTB = TMR0L;
}while(INTCONbits.TMR0IF==0);
T0CONbits.TMR0ON = 0;
INTCONbits.TMR0IF = 0;
}
}
and the compiler gives error "c; 15.1 undefined identifier "T0CON"" and same with T0CONbits, INTCON.... I wonder if these registers are called by some other names in Hi Tech compiler..................
One of the most important differences between the PIC16 and PIC18 series, in regards to your code, is the fact that the PIC18 series has a 16-bit TMR0, while the PIC16 series has an 8-bit TMR0, also the TMR0 in the PIC16 is not controlled by its own "Control Register" as it is in the PIC18. Controlling the TMR0 in the PIC18 is accomplished by manipulating the bits of both the INTCON and OPTION_REG registers.
When first learning to program a new device, it is essential you first obtain/download the devices datasheet:
Microchip's PIC16F877A Info Page
PIC16F87XA Datasheet PDF
There are almost always major differences between different devices of the same series, so studying the datasheet of your actual device is vital.
Hope the suggestions help in your endeavors.