Defines PIN in XC compiler

Status
Not open for further replies.

embpic

Advanced Member level 3
Joined
May 29, 2013
Messages
742
Helped
80
Reputation
160
Reaction score
77
Trophy points
1,308
Location
india
Visit site
Activity points
5,213
Hello master's
i am using pic16f876a controller and it's my starting to PIC controller's. how to define pins in XC compiler. and how to use port to send data and do ANDing with the port's data.
 


Code C - [expand]
1
2
3
4
5
6
7
8
#define LED PORTBbits.RB0
#define LED LATBbits.RB0
#define LEDPORT PORTB
#define LEDPORT LATB
#define LCDRSDIR TRISBbits.TRISB0
 
PORTB = myData;
PORTB = PORTB & 0x01; //PORTB will be 1 after assigning

 

how to define ISR routine function.

is there any difference in define the pins in Hi-Tech and this compiler.
if i done the task on proteus will 100% run on hardware.
 

i define as you give the way but it is not working
i have posted my code as follow
using xc 8-bit compiler
mplab x ide
pic16f876a

Code:
void enable();
void init_lcd();
void data_map(char);
void command_write(unsigned char);
void data_write(unsigned char);
void swap(char );
void delay(unsigned int);
void delay_us(unsigned int del);

#define rs PORTCbits.RC0
#define rw PORTCbits.RC1
#define E PORTCbits.RC2


void init_lcd()
{
	delay(15);
	command_write(0x03);
	delay(5);

	command_write(0x03);
	delay(5);

	command_write(0x03);
	delay(5);

	command_write(0x02);
	delay(5);

	command_write(0x28);
	delay(5);

	command_write(0x01);
	delay(5);

	command_write(0x0c);
	delay(5);
}

void data_map(unsigned char ds)
{
unsigned char ab;
	ab=ds;
	PORTC = PORTC & 0x0f;
	ab=ab&0xf0;
	PORTC =ab | PORTC;
}


void command_write(unsigned char c_dt)
{
	rs = 0;
	rw = 0;
	data_map(c_dt);
	enable();
	c_dt=c_dt<<4;
	data_map(c_dt);
	enable();
}


void data_write( char d_dt)
{
	rs = 1;
	rw = 0;
	data_map(d_dt);
	enable();
	d_dt=d_dt<<4;
	data_map(d_dt);
	enable();
}


void delay(unsigned int val)
{
unsigned int n,m;
	for(n=0;n<val;n++)
		for(m=0;m<=120;m++);
}

void enable()
{
    E = 1;
    delay_us(10);
    E = 0;
}

void print(unsigned char *ptr,unsigned char addr)
{
	command_write(addr);
	while(!(*ptr=='\0'))
	{
		data_write(*ptr++);
		delay(2);
	}
}

void delay_us(unsigned int del)
{
    for(;del>0;del--);
}
 


Code C - [expand]
1
2
3
4
5
#include <xc.h>
 
#define _XTAL_FREQ 4000000
 
//#pragma config......... here



Use PORTC for RS, RW, EN and PORTB for LCD data. I don't see TRISx settings in the code.
 

yes sir this setting remain to add but the lines as follows are giving error
PORTC = PORTC & 0x0f;
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…