You are not logged in.

TSM

La Nicchia

  • "TSM" is male
  • "TSM" started this thread

Posts: 25

Date of registration: Aug 29th 2008

Location: Napoli, Italia

  • Send private message

member since 54 month member since 54 month member since 54 month

1

Saturday, October 18th 2008, 11:35am

How I added a 7 segment display

Hello, I managed to add a 7 segment display to MMC2IEC, with minimal hardware modification and a little bit of code. Its purpose is to show the currently mounted disk image when a swaplist is active (in HEX). I used the following part (common anode type):
http://www.digchip.com/datasheets/parts/…/ELS-432EWA.php

I modified the hardware variant nr. 2 this way:

- Busy & Dirty LEDs moved to PD4/PD3
- No Debug LED
- Next & Prev buttons moved to PB0/PB1

Then I connected the display:

- Pin 3 to +5V
- Pin 10 (segment A) to PC0 through a 560 Ohm resistor
- Pin 9 (segment B) to PC1 through a 560 Ohm resistor
- Pin 7 (segment C) to PC2 through a 560 Ohm resistor
- Pin 5 (segment D) to PC3 through a 560 Ohm resistor
- Pin 4 (segment E) to PC4 through a 560 Ohm resistor
- Pin 2 (segment F) to PC5 through a 560 Ohm resistor
- Pin 1 (segment G) to PC6 through a 560 Ohm resistor

I took the source version 0.6.6.

This is the code I added to main.c (I put it before "BUSY_LED_SETDDR();"):

Source code

1
2
3
4
// Set all PORTC pins as outputs
DDRC = 0xFF;
// Turn off all the segments
PORTC = 0xFF;


All the remaining code changes were made to diskchange.h.

I put this declaration at the beginning:

Source code

1
2
3
4
5
// the code for the digit '0' was put at the end, to show
// the number '1' when the first disk is mounted

const unsigned char c[] = {0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x00,
                                 	0x10,0x08,0x03,0x46,0x21,0x06,0x0E,0x40};


Then, everywhere I found something like this:

Source code

1
2
if (mount_line())
	confirm_blink(BLINK_something);


i changed it this way:

Source code

1
2
3
4
if (mount_line()) {
	confirm_blink(BLINK_something);
	PORTC = c[linenum%16];
  }


That code appears 4 times. The reason why I used the modulus is to simulate the presence of another display for a virtual extra HEX digit and most of all, to avoid the risk of going outside the array boundaries.

Important: remember to disable JTAG in the fuse settings if you're going to do this modification.

That's it. It seems to work quite well, although I haven't extensively tested it yet. If you find it of any use, you may want to add it to the official sources (Unseen?).

I take no responsibility whatsoever if someone tries doing it and destroys hardware or data!! :whistling:

Unseen

Hätte gerne 'n Virtex 7 ;)

  • "Unseen" is male
  • »Unseen« is a verified user

Posts: 4,576

Date of registration: Jun 16th 2007

Location: Debara Hamtar

  • Send private message

member since 72 month member since 72 month member since 72 month member since 72 month

2

Saturday, October 18th 2008, 11:53am

RE: How I added a 7 segment display

I put this declaration at the beginning:

Source code

1
2
3
4
5
// the code for the digit '0' was put at the end, to show
// the number '1' when the first disk is mounted

const unsigned char c[] = {0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x00,
                                 	0x10,0x08,0x03,0x46,0x21,0x06,0x0E,0x40};

If you add PROGMEM to this declaration the array contents will only be stored in flash, the way you declared it it's stored in flash and gets copied to ram during the initialisation. I don't remember how much "spare" ram I had on the ATmega32 with 0.6.6, but I think it wasn't much. The stack can grow quite large in some code paths.

Quoted

Source code

1
2
3
4
if (mount_line()) {
	confirm_blink(BLINK_something);
	PORTC = c[linenum%16];
  }

With a PROGMEM declaration of c that would need to be "PORTC = pgm_read_byte(c+(linenum%16))" because gcc doesn't really know about Havard architectures.

Quoted

Important: remember to disable JTAG in the fuse settings if you're going to do this modification.

main() disables JTAG in software already because otherwise the disk change button didn't work.

Quoted

If you find it of any use, you may want to add it to the official sources (Unseen?).

I'll think about it, but if I do I'll probably abstract it a bit and use Yet Another Config Option.

You may want to take a look at the MAX7221. It's a bit expensive (unless you order a free sample), but a single chip can multiplex up to eight 7-segment-displays without external components. It could be connected in parallel to the SD card (just use a different pin for the MAX CS line and maybe leave out the MAX DO to AVR MISO connection) to get more than one digit without rearranging even more pins.

Quellcode

1
2
3
10 x=rnd(-1963):fori=1to81:y=rnd(1):next
20 forj=1to5:printchr$(rnd(1)*16+70);:next
30 printint(rnd(1)*328)-217

sd2iec Homepage

TSM

La Nicchia

  • "TSM" is male
  • "TSM" started this thread

Posts: 25

Date of registration: Aug 29th 2008

Location: Napoli, Italia

  • Send private message

member since 54 month member since 54 month member since 54 month

3

Saturday, October 18th 2008, 12:11pm

I don't remember how much "spare" ram I had on the ATmega32 with 0.6.6, but I think it wasn't much. The stack can grow quite large in some code paths.
How can I check if the chip goes out of memory? :gruebel

Unseen

Hätte gerne 'n Virtex 7 ;)

  • "Unseen" is male
  • »Unseen« is a verified user

Posts: 4,576

Date of registration: Jun 16th 2007

Location: Debara Hamtar

  • Send private message

member since 72 month member since 72 month member since 72 month member since 72 month

4

Saturday, October 18th 2008, 12:16pm

How can I check if the chip goes out of memory? :gruebel

There is a compile-option to add stack size tracking, but it increases the code size a lot - it won't fit in the mega32 anymore. Another way would be to fill the free memory with a known value (it's initialized to 0 by default), periodically create a ram dump using the JTAG debugging interface and check where the value was overwritten - the stack has grown at least that large during execution. I haven't tried the second way yet although I know someone who does something similiar for commercial AVR software development.

Or you could just wait until you see strange behaviour and/or corrupted data. ;-)

Quellcode

1
2
3
10 x=rnd(-1963):fori=1to81:y=rnd(1):next
20 forj=1to5:printchr$(rnd(1)*16+70);:next
30 printint(rnd(1)*328)-217

sd2iec Homepage

Telespielator

▬▬INFERIOR▬▬ NEU: Hotline (i.d.R. Mi. 21-22 Uhr): 01573/17-64-64-4 ▬▬▬▬ Swappen?►Mail!

  • "Telespielator" is male
  • »Telespielator« is a verified user

Posts: 11,693

Date of registration: Jul 30th 2005

Location: Bonn

Marketplace entries: 2

  • Send private message

member since 90 month member since 90 month member since 90 month member since 90 month member since 90 month

5

Saturday, October 18th 2008, 12:51pm

Fotos! Fotos! Fotos! :dafuer: :winke: :roll2:
Bitte beachten: Telespielatorgesetz (TspG)
Verstöße gegen das TspG werden umgehend und gnadenlos von Supererdbeeregeahndet!

TSM

La Nicchia

  • "TSM" is male
  • "TSM" started this thread

Posts: 25

Date of registration: Aug 29th 2008

Location: Napoli, Italia

  • Send private message

member since 54 month member since 54 month member since 54 month

6

Saturday, October 18th 2008, 1:48pm

Fotos! Fotos! Fotos!
Here's the board I use for testing (nothing spectacular for sure!):



The final goal is to mount the display inside this thing: