I am using MPLABX to write a simple program for PIC 18LF46K42 Microcontroller that would turn LEDs on and off after a certain delay. The compiler does not recognize "TRISB" and "LATB" registers. It looks like that I am missing some header files. I am not sure what the issue is. I am using a CCS C Compiler. Here is my code:
include <18LF46K42.h>
#include <stdio.h>
#include <stdlib.h>
#define SCL_PIN PIN_C3
#define SDA_PIN PIN_C4
// I2C declaration code
#pin_select SCL1OUT = SCL_PIN
#pin_select SCL1IN = SCL_PIN
#pin_select SDA1OUT = SDA_PIN
#pin_select SDA1IN = SDA_PIN
#use delay(internal=16Mhz)
#use rs232(baud=4800, stream=RS232_2 , xmit=PIN_E1, rcv=PIN_E0, timeout=2000)
#use i2c(I2C1,stream=IICBUS, master, FORCE_HW)
void delay_ms ( int delay );
void delay_ms ( int delay )
{
int ms, i;
for ( ms = 0; ms < delay; ms ++ )
for ( i = 0; i < 5; i ++ );
}
void main()
{
TRISB = 0x00; // Set PORTB as output PORT
LATB = 0xFF; // Set PORTB high initially (All LEDs on)
while ( 1 )
{
LATB = ~LATB; // Toggle the value of PORTB
delay_ms ( 1000 ); // Delay of 1 sec
}
}
I get the following errors:
C:\MicrocontrollerTest\PIC18Test.X\main.c:39:4: Error#12 Undefined identifier TRISB:
C:\MicrocontrollerTest\PIC18Test.X\main.c:40:4: Error#12 Undefined identifier LATB:
C:\MicrocontrollerTest\PIC18Test.X\main.c:44:4: Error#12 Undefined identifier LATB:
I am not sure if I need to use a different compiler or am I missing any header file.