'****************************************************************
'* Name : 7 seg test from pic basic pro chapter6.5.BAS *
'* Author : ray *
'* VIEW...EDITOR OPTIONS] *
'* : *
'* Date : 9/26/2013 *
'* Version : 1.0 *
'* Notes : using pic16f628 2 digits 0 to 99 *
'* : *
'******************************************************************
define osc 4
define oscal_2k 1
cmcon = 7
Digit var byte 'Value of number to be displayed
Mask var byte 'Mask of number to be displayed
W var byte 'temporary variable digit
i var byte 'temporary variable
LEDDis1 var PORTA.1 'Transistor for ones digit
LEDDis2 var PORTA.0 'Transistor for tens digit
TRISA=%00000000 'all pins of port A are output
TRISB=%00000000 'all pins of port B are output
LEDDis1=0 'ones digit is off at the start
LEDDis2=0 'tens digit is off at the start
INTCON = %00100000 'Enable interrupt TMRO
OPTION_REG = %10000000 'Initialization of presraler
On Interrupt Goto ISR 'Interrupt vector
INTCON = %10100000 'Enable interrupts
W=0 'Initialization of variable W
Main: 'Beginning of the program
for i=1 to 99 'Print values from 0 to 99 displayed
W=W +l 'Increase variable W
Gosub Prepare 'Prepare value from W to be displayed
pause 500 'Pause to see the digits
next i
goto Main 'Print values from 0 to 99 again
Prepare:
Digit=W dig 1 'Value of ones is put to var. Digit
Gosub bin2seg 'Converting digit to mask
Maskl=Digit 'Mask 1 contains the mask of ones
Digit=W dig 0
Gosub bin2seg 'Converting digit to mask
Mask2=Digit 'Mask 1 contains the mask of tens
Return 'Return from subroutine
bin2seg:
Lookup Digit,[$3F,$06,$5B,$4F,$66,$6D,$7D,$07,$7F,$6f],Cifra
Return
Disable 'Disable interrupts while ISR is executing
ISR:
PORTB=Mask1 'Put a mask of tens digit to port B
LEDDis2=1 'Print the ones digit
pause 1 ' hold it printed for 1 ms
LEDDis2=0 'turn off the tens digit
PORTB=Mask2 'Put a mask of ones digit to port B
LEDDisl=1 'Print the ones digit
pause 1 'Hold it printed for 1 ms
LEDDisl=0 'turn off the ones digit
INTCON.2 = 0 'Clear TOIF flag
resume 'return to program
Enable 'Interrupts are enabled again
End 'End of program