• AVR Freaks

Hot!PIC16F877A Attempting to adapt code to XC8 compiler from micro C

New Member
  • Total Posts : 1
  • Reward points : 0
  • Joined: 2020/03/19 11:59:31
  • Location: 0
  • Status: offline
2020/04/01 06:38:28 (permalink)

PIC16F877A Attempting to adapt code to XC8 compiler from micro C

Hi, im working on a project and found a solution to my problem however the code was written in micro C and since im very new to both ways of programming micro-controllers I realy could use some help, like i said im using the XC8 compiler, PIC16F877A, and a pickit3 to download the code to the chip. Here is the code that im attempting to adapt.   
sbit LCD_D7 at RB2_bit;
sbit LCD_D6 at RB3_bit;
sbit LCD_D5 at RB4_bit;
sbit LCD_D4 at RB5_bit;
sbit LCD_EN at RB6_bit;
sbit LCD_RS at RB7_bit;

sbit LCD_D7_Direction at TRISB2_bit;
sbit LCD_D6_Direction at TRISB3_bit;
sbit LCD_D5_Direction at TRISB4_bit;
sbit LCD_D4_Direction at TRISB5_bit;
sbit LCD_EN_Direction at TRISB6_bit;
sbit LCD_RS_Direction at TRISB7_bit;
// End LCD module connections
//******************************frequency meter variables*******
int value,freq,humidity;
char humid[7];
void data_converstion(void)
IntToStr(humidity, humid);
void display1(void)

lcd_out(1,1,"Humidity = ");
lcd_out(1,13, Ltrim(humid));
Lcd_Chr_Cp(' ');


void interrupt(void) // high portD
T1CON.TMR1ON=1; // turn on the timer1
INTCON.INTF = 0; // clear the interrupt flag
else if(T1CON.TMR1ON==1)
T1CON.TMR1ON=0; // turn off the timer1
INTCON.INTE = 0; //Enable RB0/INT external Interrupt
humidity = 565 - freq/13;
// freq = freq /13.18;
//freq = 100 - freq;
INTCON.INTE = 1; //Enable RB0/INT external Interrupt
INTCON.INTF = 0; // clear the interrupt flag

void main()
long count;

TMR1L=0; // intialization of timer one prescalar and internal clock
INTCON.GIE = 1; //Enable Global Interrupt
INTCON.INTE = 1; //Enable RB0/INT external Interrupt
OPTION_REG.INTEDG = 0; //Interrupt on rising edge
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // Clear display
lcd_out(1,4,"GREEN HOUSE");
Lcd_Cmd(_LCD_CLEAR); // Clear display




2 Replies Related Threads

    Super Member
    • Total Posts : 27115
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: PIC16F877A Attempting to adapt code to XC8 compiler from micro C 2020/04/02 15:11:49 (permalink)
    The first section can be changed to

    #define LCD_D7 PORTBbits.RB2
    #define LCD_D6 PORTBbits.RB3
    #define LCD_D5 PORTBbits.RB4
    #define LCD_D4 PORTBbits.RB5
    #define LCD_EN PORTBbits.RB6
    #define LCD_RS PORTBbits.RB7

    #define LCD_D7_Direction TRISBbits.TRISB2
    #define LCD_D6_Direction TRISBbits.TRISB3
    #define LCD_D5_Direction TRISBbits.TRISB4
    #define LCD_D4_Direction TRISBbits.TRISB5
    #define LCD_EN_Direction TRISBbits.TRISB6
    #define LCD_RS_Direction TRISBbits.TRISB7

    However the rest of the code is calling MikroC library functions which are not present in XC8.
    There are tons of posts on this forum talking about connecting simple LCD displays to PICs.
    There's also a good one over at http://picforum.ric323.co...pic.php?f=40&t=210
    Be aware, the ancient PIC16F877 has a number of limitations with its port registers that can cause unexpected problems. Newer PIC16F1xxx chips fix this, and are usually cheaper as well.

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    Super Member
    • Total Posts : 2677
    • Reward points : 0
    • Joined: 2006/06/27 16:11:32
    • Location: Cockeysville, MD, USA
    • Status: online
    Re: PIC16F877A Attempting to adapt code to XC8 compiler from micro C 2020/04/02 21:22:11 (permalink)
    5 (2)
    About three years ago I was working on a project originally written for MikroC. So I tried to make a compatible LCD library. Here is one thread about that:
    Here is the library:
    IIRC it works for a PIC16F887. I think it is fairly similar to your 877A.

    Jump to:
    © 2020 APG vNext Commercial Version 4.5