Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

digital input to pic microcontroller

Status
Not open for further replies.

pisces12

Junior Member level 2
Joined
Dec 2, 2009
Messages
22
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
malaysia
Activity points
1,436
hi...

is it possible if i want to give bcd input into pic16f877? the bcd input is from latches that have 8 bit output....
 

CMOS or TTL levels are within PIC's range - see attached Input Level Comparison ..
Also visit this site:
**broken link removed**

Rgds,
ianP
 

Hi pisces12,
Yeah, why not? It is possible. All you need to do is read the value on the port and then use a suitable routine to convert this BCD data to decimal. Something like this in mikroBASIC would be:
Code:
dim a as byte
'If PORTB were the port where BCD is input
a = BCD2Dec(PORTB)
mikroC:
Code:
unsigned char a;
a= BCD2Dec(PORTB);
These examples will only work on mikroC and mikroBASIC. Other compilers may/may not have routines/libraries for converting BCD to Decimal. It is also possible to do the conversion yourself.

Such a conversion in C would be:
Code:
unsigned char a;
a = ( ( (PORTB & 0xF0) / 10 ) << 4) + (PORTB & 0x0F) ;
BASIC:
Code:
dim a as byte
a = ( ( (PORTB and 0xF0) div 10) << 4) + (PORTB & 0x0F) ;

Let me know if it worked for you.
Hope this helped.
Tahmid.
 

tq for the answer and note...

Added after 46 minutes:

to tahmid...

unsigned char a;
a = ( ( (PORTB & 0xF0) / 10 ) << 4) + (PORTB & 0x0F) ;

what does this code mean?can u kindly explain it further...
for example i have input 11001000 and i want to assign it equal to 360 degree..how can i write the code?this input is for the counter to increase it reading by 1 each time it cross the x-axis of the sine wave...
 

Hi,
The conversion goes as follows:
If you have a bcd value of 22 and it is assigned to PORTB then,
PORTB = 22(BCD)
therefore PORTB & 0xF0 = 20
PORTB & 0x0F = 2
So,
(PORTB & 0xF0) / 10 = 20 / 10 = 2
( ( (PORTB & 0xF0) / 10 ) << 4) = 2 << 4
<< 4 = bitshifting left 4 times, which means mulitplying by 16
2 << 4 = 2 * 16 = 32
Therefore,
( ( (PORTB & 0xF0) / 10 ) << 4) + (PORTB & 0x0F) = 32 + 2 = 34
So BCD 22 = decimal 34 or hex 22
I don't understand this:
Code:
 i have input 11001000 and i want to assign it equal to 360 degree..how can i write the code?this input is for the counter to increase it reading by 1 each time it cross the x-axis of the sine wave...
11001000 is 0xA8 in hex. This is not a valid BCD value.
 

ok...tq for the explanation of the code...

basically, i want to design digital watthour meter..i have two zero crossing detector circuit which one is for voltage and another one is for current..the output from the zero crossing detector of voltage will be the input for the 8 bit binary counter. the output from the zero crossing detector of current will be the input for the latches..the zero crossing detector (voltage) means the zero crossing detector that detect the time when the voltage of the system is crossing xaxis. this detector output will clear the counter and the counter will start count again from 00000000. when the zero crossing detector (current ) has detected that the current is crossing zero, the triggering signal will latch the digital signal to the pic. 00000000 is used to represent phase shift = 0 and 11001000 represent phase shift = 360. so, basically the function of the zero crossing detector and the counter is to calculate the phase shift..
 

hi...

what is the difference between bcd and binary code?
 

how does the binary input to pic microcontroller is converted to decimal?for example input = 11001000...can anyone give example code in C...
 

hello pisces12,

you said you were going to make a wattmeter. I am going to do the same thing. From which device would you get your current/ voltage? As for us, we're going to use an analog clampmeter and tamper its circuit where we can get the values as input to the PIC. What do you think about this?

Your reply would be appreciated.
Thank you very much.

Sincerely,

Heina
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top