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.

Questions on upgrading my Project

Status
Not open for further replies.

Sloetyme

New Member
I have completed a free project posted from "Talking Electronics website - http://talkingelectronics.com/projects/15x7Display/15x7Display-1.html". I upgraded the code from 16f84 to 16f628a before the site had updated theirs. The project worked great all buttons worked the way they are programmed to. The orientation as you see below in ATTACHMENT#1, the LEDS are in a setup of Anode Columns and Cathode Rows.

Well I have duplicated this project again using male and female pin headers to attach multiple boards and I want to upgrade the led board to three 5x7 LED Display Modules(datasheet is ATTACHMENT#2 below), LTP-2157AKA. I was in a hurry while ordering from DIGIKEY and didn't pay attention to what I was buying. I ordered a module with Anode Rows and Cathode Columns.

My question is: Can I switch something up to be able to use these modules or order a different set? All help would be awesome.
 

Attachments

  • 15x7LED-Array.gif
    15x7LED-Array.gif
    30.6 KB · Views: 205
  • LTP2157AKx.pdf
    227.4 KB · Views: 316
It can be done, but I don't have time to work it out in detail at the moment.

However, yoiu may have to make some small changes to the PIC programme.

Are you able to do this?
 
If you were able to change the program, it should be no problem changing the outputs to be inverted, right?
Then you would just need to swap the NPNs for PNPs and swap the +5v and gnd rails going to them. If youre doing this on a breadboard it should be easy to change the rails, on a ready made pcb it might be harder.
 
Yes I can make changes as I have the orginal code. I would take a little longer than most to change it up. as far as the rails being changed is where i get lost. I am making some breakout boards for prototyping this project. I appreciate the responses.
 
Last edited:
I have studied the circuit & I have found it is more complicated than I thought.

The complication is due to the buttons.

I'll need to think about it further to resolve this issue.
 
Ok
Len. I'm using tactile momentary push-buttons.
I will make what I call some more "breakout boards" tomorrow.
I also will attach the code if that will add more help.
Talk to you later.
Good Night,
Tom
 
Tom,
The type of button is irrelevant to the issue.

The issue is related to the fact that we need to transpose the collectors and emitters of the column driving transistors so they become inverting switches is rather than emitter followers.

However, once we do that, it prevents the button function from operating.

In the attached diagram, I have only altered one of the column driving transistors, one LED and one of the row driving transistors in order to show you the basic idea.

The solution I have thought of is to use MOSFETs (such as the 2N7000) in lieu of the NPN bipolar transistors that are associated with the button function, i.e. those inside the red box on the diagram.

The 7 transistors at the bottom, i.e. the row the drivers, must also be transposed so they become emitter followers rather than inverting switches.

I don't need to see the code since this arrangement means that you will not have to change the programme.

The MOSFETs should be connected such that the sources are connected to ground, the drains are connected to the 82R resistors and the gates to the 1K5 resistors.

You will have to isolate the tracks as shown in the drawing so that the 5 Volt is connected to the collectors of the row driving transistors and ground is connected to the emitters (and the MOSFET sources) of the column drivers.

You should check where the tracks go to ensure that you are not isolating something that should not be
isolated.

If you have any questions, just ask.
 
Ok I will try this route, I have plenty of 2n7000's to play with. I like the idea you came up with. Gimme a couple of days to proto-type this and i will respond will results. Your thoughts were great.
 
Tom,
If you have plenty of 2N7000's available, then all of the column drivers can be 2N7000 if you wish.

If so, you can use the 2k2 resistors on their gates in lieu of the 1k5 resistors I indicated.

The resistors are much less critical for the MOSFETs than for the bipolars, since the bipolars need sufficient base current to be reliably saturated. (the base current needs to be at least 10% of the collector current).

I estimated that the collector current will be about 28 mA, ie. there will be 28 mA through the LED that is on.

Later, I'll do an edit and post a simplified drawing of the arrangement as it will be easier to see how it works.
 
If you were able to change the program, it should be no problem changing the outputs to be inverted, right?
Then you would just need to swap the NPNs for PNPs and swap the +5v and gnd rails going to them. If youre doing this on a breadboard it should be easy to change the rails, on a ready made pcb it might be harder.

This would not work for the row drivers since the 4017 outputs are Active High and this can't be changed unless you used inverters.
 
I decided to add a new post rather than edit post #9.

Here is the simplified drawing I mentioned. This should make it easlier to see how it works.

EDIT. I had neglected to include the 82R resistors.

I have now included them in the amended drawing & I have included some notes in green.

If you are intending to make your own PCB, then the green comments show how the circuit can be simplified.
 
Last edited:
This would be a better option, but it would need significant changes to the programme - or write a new programme.

The programme will be simpler since the buttons logic is much simpler.

Description
I don't know which way the LEDs are scanned, so I'll assume for the purpose of this explanation, that the scan starts at row 1, column 1 then goes to row 1, column 2 ... row 1, column 15, then goes to row 2 column 1, etc.

Note that I have suggested that the column drivers are MOSFETs, but NPN transistors could be used instead if you prefer.

During the initialisation sequence, the PIC sets RA4 briefly in order to reset the 4017.

Then it sets RB1 in order to turn the first NPN transistor on thus addressing row 1.

It then sets RA7 briefly in order to increment the 4017 so that outlet 1 goes high.

This turns the first MOSFET on thus addressing column 1 - hence turning the first LED is on.

The Up button is connected to RB1, the Down button to RB2, etc.

So if the Up button is pressed while RB1 is set, RB0 goes high thus alerting the PIC that the Up button is pressed so it can perform the appropriate function.

At the end of the scan period, RA7 is set briefly in order to increment the 4017 so the outlet 2 goes high.

This addresses column 2 hence turning the second LED is on.

This process continues until column 15 is addressed.

At the end of this scan period, the PIC sets RA4 high briefly in order to reset the 4017.

It then clears RB1 and sets RB2 to address row 2 and then sets RA7 briefly in order to increment the 4017 so that outlet 1 goes high to address column 1.

If the Down button is pressed, RB0 goes high thus alerting the PIC that the Down button is pressed so it can perform the appropriate function.
 
Last edited:
Here is another option, this one eliminates many of the discrete components by using two integrated circuits.

However, it requires some programme changes.

Description

During the initialisation sequence, the PIC sets RA to 10-- -001 & clears RB (- = don't care).

This makes U1 output 1 low thus activating Column 1.

Then the PIC sets RB1 which turns the first NPN transistor on thus activating row 1 - hence turning the first LED is on.

At the end of this scan period, RA0 is cleared & RA1 is set thus U1/1 goes high & U1/2 low.

This activates column 2 hence turning the second LED is on.

The RA2:0 outputs are changed at the end of each scan period in a binary sequence so Columns 3 ~ 7 are activated in turn.

At the end of the seventh scan period, RA2:0 are cleared, RA6 is set & RA7 is cleared.

This activated Column 8.

As before, RA2:0 are changed at the end of each scan period in a binary sequence so Columns 9 ~ 15 are activated in turn.

At the end of the 15th scan period, RA is again set to 10-- -001, RB7 is set & RB6 is cleared.

This reactivates Column 1. RB1 is cleared & RB2 is set thus activating row 2.

This process continues until all LEDs have been addressed & then the first LED is re-addressed as described above.
 
Last edited:
Here is another option, this one eliminates many of the discrete components by using two integrated circuits.

However, it requires some programme changes.

Description

During the initialisation sequence, the PIC sets RA to 10-- -001 & clears RB (- = don't care).

This makes U1 output 1 low thus activating Column 1.

Then the PIC sets RB1 which turns the first NPN transistor on thus activating row 1 - hence turning the first LED is on.

At the end of this scan period, RA0 is cleared & RA1 is set thus U1/1 goes high & U1/2 low.

This activates column 2 hence turning the second LED is on.

The RA2:0 outputs are changed at the end of each scan period in a binary sequence so Columns 3 ~ 7 are activated in turn.

At the end of the seventh scan period, RA2:0 are cleared, RA6 is set & RA7 is cleared.

This activated Column 8.

As before, RA2:0 are changed at the end of each scan period in a binary sequence so Columns 9 ~ 15 are activated in turn.

At the end of the 15th scan period, RA is again set to 10-- -001, RB7 is set & RB6 is cleared.

This reactivates Column 1. RB1 is cleared & RB2 is set thus activating row 2.

This process continues until all LEDs have been addressed & then the first LED is re-addressed as described above.

I very much like this the best.

I ordered some 74ls145's from NTE and waiting for them....in the meantime I'm gonna try and see if cd4028 will work.

Sorry took sooo long to respond! I'm here daily.

Talk tomorrow if i find out something.
 
Last edited:
I very much like this the best.

I ordered some 74ls145's from NTE and waiting for them....in the meantime I'm gonna try and see if cd4028 will work.

Sorry took sooo long to respond! I'm here daily. No problem, I have many other things to do.

Talk tomorrow if i find out something.
Don't bother trying a CD4028.

It has 2 problems:-

1. It has Active High outputs (you need Active Low)

2. It cannot source or sink the current you need.
 
In training now because these 35 instructions are driving me nuts....lol.....I'm refreshing my memory for a bit and see what I'm doing and accomplish this new code for Post #13. Get back to you later Len with some of this task completed.
 
Have you done any PIC programming in Assembly before?

If not, it would be a good idea to start with a simple porgramme.

I can post some if you wish.
 
Have you done any PIC programming in Assembly before?

If not, it would be a good idea to start with a simple porgramme.

I can post some if you wish.

Hi Len,
Sure I have followed a many of tutorials in assembly also I am right now reading up on the mid range mcu instruction set which I wish I would have done this before now. I have a book about pic programming, read through it three times and still a little lost, it is explained in assembly code.

I am grateful for any ideas....and myself doing the work of course...lol....I will be waiting your return. Good day to ya.

Tom
 
Last edited:
Tom,
I suggest that you post some examples of code that you don't understand so I & others can help.

Below is a Traffic Lights programme that is relatively simple. I think I used the delay sub routine from one of Nigel's tutorials. However, there are other ways to do delays.

Note that - although I used the "RB change interrupt" - I did not use an interrupt sub routine (ISR).

ISRs can cause some complications & are not always necessary as this example shows.

In other words, you can use the interrupt facilities without necessarily employing an ISR.

PS. What does the PIC do? In other words, what are the effects of pressing the various buttons?

Code:
;Programme function - Simulate pedestrian traffic lights
;The push button is connected to RB7.  It should be connected 
; such that it is set when the button is pressed.


              LIST   P=PIC16F84,	F=INHX8M
            include "p16f84.inc"
             __CONFIG 0x3FF2	;4 MHz crystal oscillator, WDT disabled, Power up reset enabled

porta	EQU     05	;porta is at address 05
portb	EQU     06	;portb is at address 06

	cblock	0x20	;start of general purpose registers
		counter8	;flash counter
		count_a		;used in delay routine
		count_b		;used in delay routine
		count_1		;used in delay routine
		count_2		;used in delay routine
	endc

	ORG     0x00

#define 	Ped_Red		porta, 0 	;Bit 0 Pedestrian's Red LED
#define 	Ped_Green	porta, 2 	;Bit 2 Pedestrian's Green LED

#define 	Motor_Red	portb, 0	;Bit 0 Motorist's Red LED
#define 	Motor_Amber	portb, 1	;Bit 1 Motorist's  Amber LED
#define 	Motor_Green	portb, 2	;Bit 2 Motorist's  Green LED

#define 	Button	portb, 7		;Bit 7 Pedestrian's button

;Programme start

start	call	Init

main	clrf	porta	; resets inputs & outputs
		clrf	portb	; ditto

		bsf		Ped_Red	;sets pedestrians; red on (RA0), others off

		bsf		Motor_Green	;sets motorists; green on (RB2), others off

		sleep		;interrupt if pedestrian's button is pressed
		nop
;the PIC will be awoken from sleep when the RB change interrupt occurs
; due to a pedestrian pressing the button which sets RB7 high

		bsf		Motor_Amber		;turns motorist's amber light on (RB1)
		bcf		Motor_Green		;turns motorist's green light off (RB2)

		call	delay_2s	;2 second delay

		movlw	0x08	;reset INTCON after a 2 sec delay so the 
		movwf	INTCON	; Pedestrian's button will have been released

		bcf		Motor_Amber	;turns motorist's amber light off (RB1)
		bsf		Motor_Red	;turns motorist's red light on (RB0)		

		bcf		Ped_Red		;pedestrian's red off (RA0)
		bsf		Ped_Green	;pedestrian's green on (RA2), 

		call	delay_8s	;creates 8 second delay

		bsf		Motor_Amber	;turns motorist's amber light on (RB1)
		bcf		Motor_Red	;turns motorist's red light off (RB0)

		movlw	08			;moves 8 into w
		movwf	counter8	;moves 8 from w into counter8

flashloop
		movlw	b'00000100'
		xorwf	porta, f		;toggles the green pedestrian light
 
		call	delay_500m		;creates half second delay
		decfsz	counter8		;8 times to flash pedestrian green

		goto	flashloop		;loops back

		call	delay_30s	;to give motorists at least 30 sec before
							; a Pedestrian can change the lights
		goto	main			;loops back to main

; Subroutines:

Init
	clrf	porta		; resets inputs & outputs
	clrf	portb		; ditto

	bsf		STATUS, 5	;selects BANK 1

	movlw	00	
	movwf	TRISA		;RA0:4 O/P Pedestrian's light: RA0 red, RA2: green
	movlw	80		;RB0:6 o/p, RB7 i/p RB3:5, not used
	movwf	TRISB		;Motorist's light: RB0: red, RB1 amber RB2: green. 
                
	movlw	b'00000111'	;sets up prescaler to divide 
	movwf	OPTION_REG	; by 256 internal clock, so TMR0 increments every 256
						; instruction cycles
		
	bcf		STATUS, 5	;selects bank 0

	movlw	0x08	;set interrupts file reg to enable
	movwf	INTCON	; the RB change interrupt

	return			;return to main programme

;delay sub routines
delay_30s				;30 sec delay
	movlw	d'60'
	goto delay_n

delay_8s				;8 sec delay
	movlw	d'16'
	goto delay_n

delay_2s				;2 sec delay
	movlw	d'4'
	goto delay_n

delay_n
	movwf	count_1
	call	delay_500m

	decfsz	count_1
	goto	$-2
	return

delay_500m				;500 millisec delay
	call	delay_250m

delay_250m	movlw	0xFA	;delay 250 mS
	goto	td0

delay_100m	movlw	d'100'	;delay 100 mS
	goto	td0

delay_50m
	movlw	d'50'	;delay 50 mS
	goto	td0

delay_20m
	movlw	d'20'	;delay 20 mS
	goto	td0

delay_5m
	movlw	0x05	;delay 5 ms (4 MHz clock)
	goto	td0

delay_1m
	movlw	0x01	;delay 1 ms (4 MHz clock)

td0	movwf	count_a	;1 ms loop * count_a
	movlw	0x63	;
	movwf	count_b
	goto	td3

td1	movlw	0x63	;
	movwf	count_b
	goto	$+1
	goto	$+1
	goto	$+1

td2	goto	$+1		;10us loop
	nop	
td3	goto	$+1
	goto	$+1

	decfsz	count_b, f
	goto	td2

	decfsz	count_a, f
	goto	td1
	return

delay_250u				;250 us
	movlw	d'81'	;
	goto	$+1
	movwf	count_a	;
	decfsz	count_a, f
	goto	$-1
	return

delay_30u
	movlw	d'8'	;delay 30 us
	movwf	count_2

	decfsz	count_2, f
	goto	$-1
	nop
	return

	ORG	0x2100
	DE	0x07, 0x0A, 0x08, 0x01

	end
 
Tom,
I suggest that you post some examples of code that you don't understand so I & others can help.

Below is a Traffic Lights programme that is relatively simple. I think I used the delay sub routine from one of Nigel's tutorials. However, there are other ways to do delays.

Note that - although I used the "RB change interrupt" - I did not use an interrupt sub routine (ISR).

ISRs can cause some complications & are not always necessary as this example shows.

In other words, you can use the interrupt facilities without necessarily employing an ISR.

PS. What does the PIC do? In other words, what are the effects of pressing the various buttons?

Code:
;Programme function - Simulate pedestrian traffic lights
;The push button is connected to RB7.  It should be connected 
; such that it is set when the button is pressed.


              LIST   P=PIC16F84,	F=INHX8M
            include "p16f84.inc"
             __CONFIG 0x3FF2	;4 MHz crystal oscillator, WDT disabled, Power up reset enabled

porta	EQU     05	;porta is at address 05
portb	EQU     06	;portb is at address 06

	cblock	0x20	;start of general purpose registers
		counter8	;flash counter
		count_a		;used in delay routine
		count_b		;used in delay routine
		count_1		;used in delay routine
		count_2		;used in delay routine
	endc

	ORG     0x00

#define 	Ped_Red		porta, 0 	;Bit 0 Pedestrian's Red LED
#define 	Ped_Green	porta, 2 	;Bit 2 Pedestrian's Green LED

#define 	Motor_Red	portb, 0	;Bit 0 Motorist's Red LED
#define 	Motor_Amber	portb, 1	;Bit 1 Motorist's  Amber LED
#define 	Motor_Green	portb, 2	;Bit 2 Motorist's  Green LED

#define 	Button	portb, 7		;Bit 7 Pedestrian's button

;Programme start

start	call	Init

main	clrf	porta	; resets inputs & outputs
		clrf	portb	; ditto

		bsf		Ped_Red	;sets pedestrians; red on (RA0), others off

		bsf		Motor_Green	;sets motorists; green on (RB2), others off

		sleep		;interrupt if pedestrian's button is pressed
		nop
;the PIC will be awoken from sleep when the RB change interrupt occurs
; due to a pedestrian pressing the button which sets RB7 high

		bsf		Motor_Amber		;turns motorist's amber light on (RB1)
		bcf		Motor_Green		;turns motorist's green light off (RB2)

		call	delay_2s	;2 second delay

		movlw	0x08	;reset INTCON after a 2 sec delay so the 
		movwf	INTCON	; Pedestrian's button will have been released

		bcf		Motor_Amber	;turns motorist's amber light off (RB1)
		bsf		Motor_Red	;turns motorist's red light on (RB0)		

		bcf		Ped_Red		;pedestrian's red off (RA0)
		bsf		Ped_Green	;pedestrian's green on (RA2), 

		call	delay_8s	;creates 8 second delay

		bsf		Motor_Amber	;turns motorist's amber light on (RB1)
		bcf		Motor_Red	;turns motorist's red light off (RB0)

		movlw	08			;moves 8 into w
		movwf	counter8	;moves 8 from w into counter8

flashloop
		movlw	b'00000100'
		xorwf	porta, f		;toggles the green pedestrian light
 
		call	delay_500m		;creates half second delay
		decfsz	counter8		;8 times to flash pedestrian green

		goto	flashloop		;loops back

		call	delay_30s	;to give motorists at least 30 sec before
							; a Pedestrian can change the lights
		goto	main			;loops back to main

; Subroutines:

Init
	clrf	porta		; resets inputs & outputs
	clrf	portb		; ditto

	bsf		STATUS, 5	;selects BANK 1

	movlw	00	
	movwf	TRISA		;RA0:4 O/P Pedestrian's light: RA0 red, RA2: green
	movlw	80		;RB0:6 o/p, RB7 i/p RB3:5, not used
	movwf	TRISB		;Motorist's light: RB0: red, RB1 amber RB2: green. 
                
	movlw	b'00000111'	;sets up prescaler to divide 
	movwf	OPTION_REG	; by 256 internal clock, so TMR0 increments every 256
						; instruction cycles
		
	bcf		STATUS, 5	;selects bank 0

	movlw	0x08	;set interrupts file reg to enable
	movwf	INTCON	; the RB change interrupt

	return			;return to main programme

;delay sub routines
delay_30s				;30 sec delay
	movlw	d'60'
	goto delay_n

delay_8s				;8 sec delay
	movlw	d'16'
	goto delay_n

delay_2s				;2 sec delay
	movlw	d'4'
	goto delay_n

delay_n
	movwf	count_1
	call	delay_500m

	decfsz	count_1
	goto	$-2
	return

delay_500m				;500 millisec delay
	call	delay_250m

delay_250m	movlw	0xFA	;delay 250 mS
	goto	td0

delay_100m	movlw	d'100'	;delay 100 mS
	goto	td0

delay_50m
	movlw	d'50'	;delay 50 mS
	goto	td0

delay_20m
	movlw	d'20'	;delay 20 mS
	goto	td0

delay_5m
	movlw	0x05	;delay 5 ms (4 MHz clock)
	goto	td0

delay_1m
	movlw	0x01	;delay 1 ms (4 MHz clock)

td0	movwf	count_a	;1 ms loop * count_a
	movlw	0x63	;
	movwf	count_b
	goto	td3

td1	movlw	0x63	;
	movwf	count_b
	goto	$+1
	goto	$+1
	goto	$+1

td2	goto	$+1		;10us loop
	nop	
td3	goto	$+1
	goto	$+1

	decfsz	count_b, f
	goto	td2

	decfsz	count_a, f
	goto	td1
	return

delay_250u				;250 us
	movlw	d'81'	;
	goto	$+1
	movwf	count_a	;
	decfsz	count_a, f
	goto	$-1
	return

delay_30u
	movlw	d'8'	;delay 30 us
	movwf	count_2

	decfsz	count_2, f
	goto	$-1
	nop
	return

	ORG	0x2100
	DE	0x07, 0x0A, 0x08, 0x01

	end

Hi Len,

Thank you for the 1st program. I would like to break it down into sections, your program, and explain what I understand or what I have learnt while showing you my calculations if that is ok.

May I Break Your CODE Into Sections and copy them to here For Experimenting Purposes?

I feel having done this(breaking up into sections) would help me understand more in detail how the program really works.

If you allow me to do this I will start with the __config word.

Before I go, I wonder if I should carry this part to a different thread in case it may be off literial topic?
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top