![]() |
![]() |
|
|||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Member
Join Date: Jun 2009
Location: Addison Texas USA
Posts: 30
|
I just purchased two PicAxe 18X chips and I'm trying to figure out just exactly how to write the code to accept a 2 digit number from the comport and output it to 8-bit BCD. I have the board almost complete and the two 74LS247 chips are accepting BCD inputs for digit 1 and digit 2 and output to a 2-digit LED display.
Where to start? I know I probably need to use SerIn to get the numbers from the comport. I will probably be 'typing' a 2-byte number to the comport from a DOS window in XP, such as 01, 24, etc. My application should accept 2-digits from the serial port, output 10's digit BCD and 1's digit BCD (i.e. 00110101 = 35). Also, if I send the output as the binary string above, will the right-most digit be on output 0 or output 7? |
|
|
|
|
|
#2 |
|
Senior Member
Join Date: Jan 1970
Location: Middle England
Posts: 2,716
|
Wayne.
Welcome to the Picaxe Forum. I'm assuming that your 7 segment displays are common Anode. Could you post your schematic please? e |
|
|
|
|
|
#3 |
|
Senior Member
Join Date: Jan 1970
Location: UK
Posts: 2,553
|
|
|
|
|
|
|
#4 | |
|
Member
Join Date: Jun 2009
Location: Addison Texas USA
Posts: 30
|
Quote:
Simply, there are two 74LS247 chips, a 10's and a 1's column driver. The 10's column fgabcde outputs go through six hex inverter inputs on the first 74LS04, and the first input on the second 74LS04. The 1's column fgabcde outputs go through the remaining 5 inverter inputs on the second 74LS04 and two inputs on the third 74LS04. The respective outputs from all three 74LS04 chips go to two separate 14 pin isolated 330 ohm resistor packs, and then to a header. A 20 conductor ribbon cable plugs into the header as well as the header on the display circuit board. The DCBA inputs on the two decoder chips will be wired to the appropriate outputs from the PicAxe18x1 chip (socket). I'm not sure but I think I recall that the serial programming connections are slightly different from the serial communications connections, or can the same cable used to program the PicAxe also be used to communicate with the PC in normal operation? |
|
|
|
|
|
|
#5 |
|
Senior Member
Join Date: Jan 1970
Location: UK
Posts: 2,553
|
The same cable can be used - look at the sertxd and serrxd commands.
A |
|
|
|
|
|
#6 |
|
Senior Member
Join Date: Jan 1970
Location: Wellington,NZ.
Posts: 2,797
|
Wayne- welcome! I'd pondered much this approach some time back with some cheap CC 7 segs to hand, intending temperature displays from a DS18B20. Following the 20M release however (which offers 8 outputs & is half the 18X price), a far simpler directly driven single sequenced display became viable. It may be worth considering in your case too- if only to lower the parts count & cost. The code was eventually deceptively simple. Stan
Last edited by manuka : 16-06-2009 at 22:58. |
|
|
|
|
|
#7 |
|
Senior Member
Join Date: Jan 2009
Location: Dunedin, New Zealand
Posts: 438
|
The code couldn't be simpler
Code:
SYMBOL pin = 1 Main: SERIN pin,T4800_4,b0 ; RS232 from PC OUTPINS = b0 GOTO Main Code:
SYMBOL pin = 1 Main: SERIN pin,N4800_4,b0 ; RS232 from PC OUTPINS = b0 GOTO Main
__________________
It would be helpful if people wouldn't make sweeping generalizations all the time. |
|
|
|
|
|
#8 |
|
Member
Join Date: Jun 2009
Location: Addison Texas USA
Posts: 30
|
I wired the outputs based on this and found it to be wrong. Fortunately I was able to program around it, so although the code isn't very elegant, it works.
Here is what I found about sending either hex or binary to the outputs of the 18x: Code:
pin: 9 8 7 6 13 12 11 10 output#: 3 2 1 0 7 6 5 4 pin value: 128 64 32 16 8 4 2 1 Since I wired up in a different order, starting with output 7 for bit 0, and working back sequentially to output 0 for bit 7, the BCD output was flipped for each nibble. The binary value for 5, for instance, should be 0101 but it was 1010 instead. Using either binary or hex resulted in the same error in the bit order. I was just about ready to tear out the 8 output lines and re-wire them when I decided to try to use a "lookup table" using gosub routines instead. It worked. I also used an asterisk (*) as a start byte. My code looks like this: Code:
main:
serin 1,n2400_4,("*"),b5,b4
b4=b4-48:b5=b5-48
on b4 gosub bin0,bin1,bin2,bin3,bin4,bin5,bin6,bin7,bin8,bin9
b0=b1*16
on b5 gosub bin0,bin1,bin2,bin3,bin4,bin5,bin6,bin7,bin8,bin9
b0=b0+b1
outpins = b0
goto main
bin0:
b1=%0000
return
bin1:
b1=%1000
return
bin2:
b1=%0100
return
bin3:
b1=%1100
return
bin4:
b1=%0010
return
bin5:
b1=%1010
return
bin6:
b1=%0110
return
bin7:
b1=%1110
return
bin8:
b1=%0001
return
bin9:
b1=%1001
return
Last edited by WayneT : 18-06-2009 at 07:02. |
|
|
|
|
|
#9 |
|
Senior Member
Join Date: Jan 1970
Location: Perth, Western Australia
Posts: 1,400
|
The 'elegant' solution you are looking for is the "LookUp" command. Refer to manual 2.
LookUp b5, (%0000,%1000,%0100......%1001), b1 |
|
|
|
|
|
#10 |
|
Technical Support
Join Date: Jan 1970
Location: UK
Posts: 13,454
|
An alternative is ...
SerIn 1, N2400_4, ( "*" ), b0, b1 b1 = b1 * 16 + b0 - $30 bit0 = bit15 bit1 = bit14 bit2 = bit13 bit3 = bit12 bit4 = bit11 bit5 = bit10 bit6 = bit9 bit7 = bit8 outpins = b0 |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|