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.

what's wrong with this chunk of code for pic16f876a

Status
Not open for further replies.

Mehmood Ahmed

New Member
this section of code has been written for getting data from tristate buffer IC using multiplexing technique but it's not working. compiler being used is HITECH C whereas I wrote same section of code using CCS C compiler and it works fine. In that version I used its library functions. I am putting here both the versions. Please suggest what wrong I am doing with HITECH C version of code. Thanks
Code:
HITECH C version

unsigned char getdata(unsigned char address)
{
 unsigned char x;
 switch(address)
 {
 case 0x1:
 	RA0 = 0;
 	TRISA0 = 0;
 	TRISB = 0xff;
 	x = PORTB;
 	RA0 = 1;
 	TRISA0 = 1;
 break;
 case 0x2:
 	RA1 = 0;
 	TRISA1 = 0;
 	TRISB = 0xff;
 	x = PORTB;
 	RA1 = 1;
 	TRISA1 = 1;
 }
 return x;
 }
CCS C version

unsigned char getdata(unsigned char address)
{
 unsigned char x;
 switch(address)
 {
 case 0x1:
 set_tris_b(0xff);
 output_bit(PIN_A0,0);
 x = input_b();
 output_bit(PIN_A0,1);
 break;
 case 0x2:
 set_tris_b(0xff);
 output_bit(PIN_A1,0);
 x = input_b();
 output_bit(PIN_A1,1);
 break;
 }
 return x;
 }
 
Last edited:
Yesterday I found the Solution by studying datasheet...port a of PIC16F876A by default is configured as analog input. So I had to configure first four bits of ADCON1 register. I set ADCON1 = 0b00000110 which made port a pins as Digital I/O that's it...Thanks for help by all of you
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top