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.

(ask) counter 3 digit 7-segment PIC

Status
Not open for further replies.

bledhuk

Newbie level 1
Joined
Jun 7, 2010
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Indonesia
Activity points
1,285
hi :D
i am trying create 3 digit counter 7 segment. Using pic and basic language
my question why 7segment brightness can not same. my program i deploy from sample program.
any one can help me?
thx in advance

original program

Code:
Dim digit As Byte  'input variable for GETMASK subroutine
Dim digit1 As Byte  'current high digit
Dim digit2 As Byte  'current low digit
Dim mask As Byte  'output variable from GETMASK subroutine
Dim mask1 As Byte  'current high digit mask
Dim mask2 As Byte  'current low digit mask
Dim i As Byte
Dim phase As Bit

Symbol d1enable = PORTC.0  'enable line for higher 7-segment display
Symbol d2enable = PORTC.1  'enable line for lower 7-segment display
TRISB = %00000000  'set PORTB pins as outputs
TRISC.0 = 0  'set RC0 pin as output
TRISC.1 = 0  'set RC1 pin as output
d1enable = False
d2enable = False
mask1 = 0
mask2 = 0
phase = 0
INTCON.T0IE = 1  'enable Timer0 interrupts
INTCON.GIE = 1  'enable all un-masked interrupts
OPTION_REG.T0CS = 0  'set Timer0 clock source to internal instruction cycle clock

loop:
For i = 0 To 99
	digit1 = i / 10  'get current high digit
	digit2 = i Mod 10  'get current low digit
	TMR0 = 0  'reset Timer0 to prevent its interrupt before both masks are determined
	digit = digit1
	Gosub getmask  'get mask for high digit
	mask1 = mask
	digit = digit2
	Gosub getmask  'get mask for low digit
	mask2 = mask
	Gosub show1  'display new mask
	Gosub show2  'display new mask
	WaitUs 500  'delay interval suitable for simulation
'use large delay for the real device, say WAITMS 500
Next i
Goto loop
End                                               

On Interrupt  'Timer0 interrupt routine
'continuously switch between high and low digit displays
If phase = 0 Then
	phase = 1
	Gosub show1
Else
	phase = 0
	Gosub show2
Endif
INTCON.T0IF = 0  'enable new TMR0 interrupts
Resume                                            

getmask:  'get appropriate 7-segment mask for input digit
	mask = LookUp(0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f), digit
Return                                            

show1:  'show high digit on its display
	d2enable = False
	PORTB = mask1
	d1enable = True
Return                                            

show2:  'show low digit on its display
	d1enable = False
	PORTB = mask2
	d2enable = True
Return

My Program:
Code:
Dim mask As Byte
Dim mask1 As Byte
Dim mask2 As Byte
Dim mask3 As Byte
Dim aaa As Word
Dim digit As Byte
Dim digit1 As Byte
Dim digit2 As Byte
Dim digit3 As Byte
Dim phase As Byte

Symbol d1enable = PORTC.0
Symbol d2enable = PORTC.1
Symbol d3enable = PORTC.2

TRISB = %00000000
TRISC.0 = 0
TRISC.1 = 0
TRISC.2 = 0

d1enable = False
d2enable = False
d3enable = False

mask1 = 0
mask2 = 0
mask3 = 0
phase = 0

INTCON.T0IE = 1
INTCON.GIE = 1
OPTION_REG.T0CS = 0

loop:
For aaa = 1000 To 0 Step -1
	digit1 = aaa Mod 10
	If aaa < 100 Then
			digit2 = aaa / 10
		Else
			digit2 = (aaa / 10) Mod 10
	Endif
	digit3 = aaa / 100
	
	TMR0 = 0

	digit = digit1
	Gosub getmask
	mask1 = Not mask

	digit = digit2
	Gosub getmask
	mask2 = Not mask

	digit = digit3
	Gosub getmask
	mask3 = Not mask

	Gosub show1
	Gosub show2
	Gosub show3

	WaitMs 500
Next aaa
Goto loop
End                                               
On Interrupt
If phase = 0 Then
	phase = 1
	Gosub show1
Endif
If phase = 1 Then
	phase = 2
	Gosub show2
Endif
If phase = 2 Then
	phase = 0
	Gosub show3
Endif
INTCON.T0IF = 0
Resume                                            

getmask:
	mask = LookUp(0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f), digit
Return                                            
show1:
	d2enable = False
	d3enable = False
	PORTB = mask1
	d1enable = True
Return                                            
show2:
	d1enable = False
	d3enable = False
	PORTB = mask2
	d2enable = True
Return                                            
show3:
	d1enable = False
	d2enable = False
	PORTB = mask3
	d3enable = True
Return


picture
11_1278154247.jpg
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top