Go Back   PICAXE Forum > Main PICAXE Forum > Active PICAXE Forum
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
Links: PICAXE Website PICAXE Manual Datasheets Online Store Software & Drivers

Reply
 
Thread Tools Display Modes
Old 16-06-2009, 18:52   #1
WayneT
Member
 
Join Date: Jun 2009
Location: Addison Texas USA
Posts: 30
Default Need help with code for Serial to 2-digit 7-segment display

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?
WayneT is offline   Reply With Quote
Old 16-06-2009, 19:12   #2
eclectic
Senior Member
 
Join Date: Jan 1970
Location: Middle England
Posts: 2,716
Default

Wayne.
Welcome to the Picaxe Forum.

I'm assuming that your 7 segment displays
are common Anode.

Could you post your schematic please?

e
eclectic is online now   Reply With Quote
Old 16-06-2009, 19:47   #3
Andrew Cowan
Senior Member
 
Join Date: Jan 1970
Location: UK
Posts: 2,553
Default

Quote:
Originally Posted by WayneT View Post
(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?
1 = output 7
0 = output 0

MSB on the left.

A
Andrew Cowan is offline   Reply With Quote
Old 16-06-2009, 21:04   #4
WayneT
Member
 
Join Date: Jun 2009
Location: Addison Texas USA
Posts: 30
Default

Quote:
Originally Posted by eclectic View Post
Wayne.
Welcome to the Picaxe Forum.

I'm assuming that your 7 segment displays
are common Anode.

Could you post your schematic please?

e
Will work up a schematic and post it when I get home from work, time permitting. No, the display unfortunately is a 2 digit Common Cathode display, but I couldn't find replacements for either the display or the 74LS247 chips locally (I got them from Mouser) so I had to do the next best thing... I added three 74LS04 Hex Inverter chips to invert the outputs from the decoders. I've already verified that grounding all BCD inputs on the 247 results in a "00" on the display, and lifting each input pin from the ground (the 247 has internal pull-up resistors) results in the appropriate digit being displayed, up through 9.

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?
WayneT is offline   Reply With Quote
Old 16-06-2009, 21:32   #5
Andrew Cowan
Senior Member
 
Join Date: Jan 1970
Location: UK
Posts: 2,553
Default

The same cable can be used - look at the sertxd and serrxd commands.

A
Andrew Cowan is offline   Reply With Quote
Old 16-06-2009, 21:37   #6
manuka
Senior Member
 
Join Date: Jan 1970
Location: Wellington,NZ.
Posts: 2,797
Default

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
Attached Images
File Type: jpg 20m7segds.jpg (113.1 KB, 63 views)

Last edited by manuka : 16-06-2009 at 22:58.
manuka is offline   Reply With Quote
Old 16-06-2009, 23:46   #7
lanternfish
Senior Member
 
Join Date: Jan 2009
Location: Dunedin, New Zealand
Posts: 438
Default

The code couldn't be simpler

Code:
SYMBOL pin = 1

Main:

SERIN pin,T4800_4,b0		; RS232 from PC
OUTPINS = b0
GOTO Main
This is assuming that you are already sending the data in BCD format. Also, that the PICAXE is interface through a MAX232 (or similar). If not then:

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.
lanternfish is offline   Reply With Quote
Old 18-06-2009, 06:40   #8
WayneT
Member
 
Join Date: Jun 2009
Location: Addison Texas USA
Posts: 30
Default It's working now

Quote:
Originally Posted by Andrew Cowan View Post
1 = output 7
0 = output 0

MSB on the left.

A
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
This means the bottom right pin (pin 10 or output 4) is LSb (least significant bit) and bottom left pin (pin 9 or output 3) is MSb.

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
I will try to post a schematic when time permits for me to draw one up. I still have some programming to do on the PC side of the equation to extract the values I need from a text file, modify the value if necessary (convert single digit numbers to zero-padded two digit numbers) and then send the start byte and number to the comport.

Last edited by WayneT : 18-06-2009 at 07:02.
WayneT is offline   Reply With Quote
Old 18-06-2009, 07:10   #9
inglewoodpete
Senior Member
 
Join Date: Jan 1970
Location: Perth, Western Australia
Posts: 1,400
Default

The 'elegant' solution you are looking for is the "LookUp" command. Refer to manual 2.

LookUp b5, (%0000,%1000,%0100......%1001), b1
inglewoodpete is offline   Reply With Quote
Old 18-06-2009, 09:10   #10
hippy
Technical Support
 
Join Date: Jan 1970
Location: UK
Posts: 13,454
Default

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
hippy is offline   Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 21:39.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
(c) Revolution Education Ltd 2007