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.

PIC16f84 binary to bcd

Status
Not open for further replies.

fraughton

New Member
for a class project, I need to take a 12-bit digital signal and output it as a decimal number to 4 7-segment displays. I know that the pic16f84 can take up to a 12-bit input if you use both ports a and b, but I dont know how to work with a 12-bit number since I can only store in 8bit registers.

Once I can work with my 12bit number i need to be able to convert it to bcd in order to use a lookup table for the output values. That is, unless there's a better way to do this.

If anyone has any suggestions or links to helpful pic programming websites I would be grateful. Thanks.

Oh ya, I'm programming in C.
 
Ignore the 12bit thing, I think I've got that covered.

If I've got a decimal value saved in memory how can I take each individual digit separately?

Here's the code i have so far:

TRISA = 0xff; //Set Port A to input
TRISB = 0xff; //Set Port B to input
inputLow = PORTB; //Take Port B input and save it to memory
lower = inputLow & 0x0f;
upper = inputLow & 0xf0 >> 4;
inputHigh = PORTA; //Take Port A input and save it to memory

n = inputHigh * pow(16,2) + upper * 16 + lower; //decimal value of input
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top