Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Compiler won't recognize registers of PIC16F876A

Status
Not open for further replies.

Cantafford

Member
Hello,

I'm trying to write a simple code in MPLAB X Ide for PIC16F876A using XC8 compiler. When I try to run the code it won't recognize my LATC registers. The microcontroller does have the TRISC registers as specified in the datasheet. Yet I get this error on any line I try to use TRISC:

"main.c:79: error: (192) undefined identifier "LATCbits""

Also I'm getting this error:
main.c:80: error: (196) struct/union required
For this line:
if(var==1) {LATCbits.LATC0 = 0; LATCbits.LATC1 = 1;} // left

What does that mean? I wrote this code for a PIC18F2550 and it worked just fine. Now I'm getting those errors but I'm not using any register name that is not in the datasheet. Also for the second error the syntax is the same so I don't think I should get an error. Yet why are the errors there?
 
Ok thank you. Can you please tell me how can I solve this error:

Code:
:0: error: undefined symbols:
        _SetDDRamAddr(dist/default/production\adc.X.production.obj) _ConvertADC(dist/default/production\adc.X.production.obj) _WriteCmdXLCD(dist/default/production\adc.X.production.obj) _ReadADC(dist/default/production\adc.X.production.obj) _BusyADC(dist/default/production\adc.X.production.obj) _putrsXLCD(dist/default/production\adc.X.production.obj) _OpenXLCD(dist/default/production\adc.X.production.obj) _BusyXLCD(dist/default/production\adc.X.production.obj) _putsXLCD(dist/default/production\adc.X.production.obj)

I have these errors for the functions in my program only when working with PIC16's. With PIC18 I don't get these errors.
 
Ah.... The XLCD lib wasn't in the mid range libraries.... Neither was the ADC library...

The reason they are not compatible is because of the latch registers (XLCD) and the ANSEL pairs (ADC)..

If you are using 4bit LCD then by all means use my library as a base... If you meander over to "Articles" and look at the "Nigels tutorials in C" compilation... You will find code there to suit your needs...

XC8 is a hybrid of C18 and HiTech.... HiTech never made libraries so you either need to grab the old C18 library source code and modify or write your own as C18 targeted only pic 18's..

If you have the latest XC8.... then the source is no longer shipped... I have them all "Nestled safely, under the tree"

Its much easier to write your own...

C:
int adc_read(unsigned char channel)
{
   ADCON0 = (channel << 2) + 0x81;     // enable ADC, RC osc.
   GODONE = 1;
   while(GODONE)
     continue;   // wait for conversion complete
   return ADRESL + ( ADRESH * 256 );
}

An LCD library... Cooked by me
C:
#include<xc.h>
#include<stdlib.h>
#include<stdio.h>


#define LCD_PORT    PORTB     // constants
#define LCD_TRIS   TRISB     //
#define LCD_RS      RB0
#define LCD_E     RB3



char lcdbuf[17];

void delayUs(int x)
   {
   x>>=5;             //<-- adjust to suit Xtal..
   while(x--);
   }
void delayMs(int x)
   {
   while(x--)
     delayUs(1000);
   }
void pulse_E()
   {
   LCD_E = 1;
   delayUs(1);
   LCD_E = 0;
   }
void LCD_cmd(unsigned char ch)
   {
   LCD_PORT = (ch & 0xf0);       // write high nibble
   LCD_RS = 0;
   pulse_E();
   LCD_PORT = (ch << 4 & 0xf0);     // write low nibble
   LCD_RS = 0;
   pulse_E();
   delayMs(5);
   }
void LCD_char(unsigned char ch)
   {
   LCD_PORT = (ch  & 0xf0);       // High nibble
   LCD_RS = 1;
   pulse_E();
   LCD_PORT = (ch << 4 & 0xf0);     // low nibble
   LCD_RS = 1;
   pulse_E();
    delayMs(5);
   }
void LCD_clr()
   {
   LCD_cmd(1);                 // Clr screen
   }  
void LCD_init()
   {
   LCD_TRIS = 0;        // outputs
   delayMs(15);
   LCD_PORT= 0x30;
   pulse_E();
   delayMs(1);
   pulse_E();
   delayMs(5);
   LCD_cmd(0x32);           // 4 bit
   LCD_cmd(0x28);           // display shift
   LCD_cmd(0x6);           // character mode
   LCD_cmd(0xc);           // display on / off and cursor
   LCD_clr();             // clear display
   }  
void LCD_line(char line)     // combines line and lineW
   {
   unsigned char data = 0x80;         // default to 1
   if(line == 2)data = 0xc0;         // change to 2
   LCD_cmd(data);
   }
void LCD_cur(char on)
   {
   unsigned char cur = 0xc;         // cursor off
   if(on) cur = 0xd;             // cursor on
   LCD_cmd(cur);
   }
void LCD_print(char* str)
   {
   while(*str != 0)
     LCD_char(*str++);
   }
void LCD_charD(unsigned char ch)
   {
   ch+=0x30;
   LCD_char(ch);             // convert to ascii
   }
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top