Buy 3-Digit Display kit

 


Buy 3-Digit Display Built and Tested


3 Digit Display
to P1    P2
Previous  PageIndexNext Page

THE FIRST STEP
Before writing a program, the first step is to make a prototype. It will give you some idea of the layout of the project and provide you with the pin numbers for the program.
The prototype can be on matrix board as produced by Talking Electronics. This board has a matrix of holes spaced at 0.1 inches with round pads for each hole. No tracks are provided on the underside of the board.
The boards provided on the market with tracks on the underside are absolutely impossible to work with as the tracks never run in the direction required.
It is absolutely absurd to wire up a prototype with trackwork that has been dictated by the board. Not only are the parts incorrectly placed but the layout is larger than required. The best solution is Talking Electronics matrix boards. The parts are soldered in place via the pads and fine enameled wire is used to make the connections. Providing these wire do not cross over, they will represent the final track-work and it is an easy matter to CAD the artwork.
Normally the segments for a display will be wired with segment "a" going to bit "0" of Port B etc but if the wiring does not allow this, the program can be changed to suit.
Once you know the pin numbers, the program can be started.
But before working on the first routine, it is handy to create a simple Flow Chart to remind you how the program will be running:

The Flow Chart shows the programming requirements and highlights the concept of creating two separate programs. If a pulse is detected on the input, the appropriate program is accessed. 
There are three uses for files in a program. They can be used for general-purpose, delays or short-term storage.
Any file can be used for any purpose and the idea of setting aside a file for a particular purpose is part of the PIC Programming Course.
By allocating files like this, the "name" or "number" of a file will remind you of its purpose and help you understand the program.
The following table is a guide:


The next step is to create the first sub-routine: SetUp. This sets up the port lines as inputs or outputs.
 

                     ;Project: 3-Digit Counter
list p=16f628 ; list directive to define processor
#include <p16f628.inc> ; processor specific variable definitions

__CONFIG _CP_OFF & _WDT_ON & _BODEN_ON & _PWRTE_ON & _ER_OSC_CLKOUT & _MCLRE_ON & _LVP_ON

; '__CONFIG' is used to put configuration data into .asm file.

SetUp





 
ORG 0
BSF 03,5
CLRF 06
MOVLW 01
MOVWF 05
BCF 03,5
CLRF 06
GOTO Look
;This is the start of memory for the program.
;Go to Bank 1
;Make all port B output
;Load W with 0000 0001
;Make RA0 input
;Go to Bank 0 - the program memory area.
;Blank the 7-segment displays
 

The next sub-routine is called "Look."
It looks at inputs 1 and 2 and determines when a pulse or voltage is present.
Input 1 detects a LOW and input 2 detects when a capacitor is charged.
When a low is detected on input 1, the micro goes to the section called "COUNTER."
If a LOW is not detected, the micro looks at input 2. On this input is a capacitor. The program discharges the capacitor and looks to see if it is has been charged. If a voltage is present on the input, the capacitor will charge and the sub-routine will take the micro to the section called "VOLTAGE."
A 100k feed-resistor has been added to the front-end of this input to detect voltages below 3.5v. This resistor will take a known time to charge the capacitor and this value is excluded from the detection process.
This is all the information you need to know to work on the Look sub-routine.
The circuit diagram is now needed to see how the interface circuitry is connected to the micro.
Input1 is normally HIGH and the activation of a push button creates a LOW.
Input2 has an RC network connected to form a time-delay arrangement. The transistor is not activated during the Look sub-routine and this simplifies the circuit.

The circuit below shows the time-delay arrangement as seen by the micro during the Look sub-routine. It sees a timing circuit made up of a 1M resistor and 1n capacitor. The 1M feed-resistor has been "greyed-out" as it forms a very small part in the of the time-delay arrangement. 

The time-delay arrangement is easy to see.
Input2 (RA1) is turned into an output line and made LOW. This discharges the 1n capacitor.
The line is then turned into an input and a short delay routine is executed. A count file is incremented and the sequence is repeated until the file reaches FFh.
If the voltage on the capacitor reaches about 3.5v, before the count file reaches FFh, a voltage has been detected and the program goes to the section called "VOLTAGE."  (The value generated by the feed-resistor must be excluded).
These facts are now put into a sub-routine called Look.
The voltage-detecting sub-routine will require some experimental values to be used during the "setting-up" of the routine as you do not know how long RA1 is required to be LOW to fully discharge the 1n capacitor. It should be almost instantaneous but allow 1mS to be on the safe side.
For the charging of the capacitor, allow a 1mS delay for each "count cycle." If no voltage is present on Input2, the 1M feed-resistor will charge the capacitor.
 

Look

Look1








Look2






Del1

Del1a

Del1b






Test
BTFSS 05,0
GOTO Pulse
BSF 03,5
BCF 05,1
BCF 03,5
BCF 05,1
CALL Del1
BSF 03,5
BSF 05,1
BCF 03,5
CLRF 60h
BTFSC 05,1
GOTO Test
CALL Del1
INCFSZ 60h,1
GOTO Look2
GOTO Look1

MOVLW 0Ah
MOVWF 3B
MOVLW 0xx
MOVWF 3A
NOP
DECFSZ 3A,1
GOTO Del1b
DECFSZ 3B,1
GOTO Del1a
RETURN

MOVLW 0A0h
SUBWF 60h
BTFSS 03,0
GOTO Voltage

MOVLW 0B0h
SUBWF 60h
BTFSS 03,0
GOTO Voltage
GOTO Look
;Test RA0 for a LOW
;Low detected, go to "Pulse" sub-routine
;
Go to Bank 1
;Make RA1 output = "0"
;Go to Bank 0 - program memory area.
;Make RA1 LOW to discharge capacitor
;LOW for 1mS
;
Go to Bank 1
;Make RA1 input = "1"
;Go to Bank 0 - program memory area.
;Zero the count file
;Is RA1 HIGH?
;RA1 is HIGH. GOTO Test to see if voltage is present
;Delay before looking again
;Increment the count file
;Do another loop
;Cycle the capacitor again

;Create 10 x 100uS = 1mS delay


;Create 25 x 4uS loops = 100uS

;4 uS loops






;This routine eliminates feed-resistor from voltage
;Assume feed-resistor generates 0A8h
;Test Carry flag. Carry is SET if W less than file 60h
;A voltage has been detected
;Pick a value above  0A8h
;
;
Test Carry flag. Carry is CLEAR if W greater than file
;A voltage has been detected
;The value was due to feed-resistor
  

Look routine above has produced two results: GOTO Pulse and GOTO Voltage.
The next routine to create is Pulse.
Pulse
is a scan routine that picks up three display values from locations 61h, 62h, and 63h.
When the count reaches 999, locations 64h, 65h, and 66h are accessed to create a 6-digit display.


SetUp











Table











Clear





Display

Disp1






Disp2
DelA






Inc



















MainP
















ORG 0
BSF 03,5
CLRF 06
MOVLW 01
MOVWF 05
BCF 03,5
CLRF 05
CLRF 1F
CLRF 11h
CLRF 12h
CLRF 13h
GOTO Main

ADDWF 02h,1
RETLW 3Fh
RETLW 06h
RETLW 5Bh
RETLW 4Fh
RETLW 66h
RETLW 6Dh
RETLW 7Dh
RETLW 07h
RETLW 7Fh
RETLW 6Fh

MOVLW 20h
MOVWF 0D
CLRF 06
CALL Disp1
RETURN

MOVLW 80h
MOVWF 0Ch
BTFSS 05,0
GOTO Disp2
BTFSC 1F,0
GOTO DelA
BSF 1F,0
CALL Inc
GOTO DelA
BCF 1F,0
NOP
DECFSZ 1A,1
GOTO DelA
DECFSZ 0C,1
GOTO Disp1
RETURN

INCF 11h,1
MOVLW 0A
XORWF 11h,0
BTFSS 03,2
RETURN
CLRF 11h
INCF 12h,1
MOVLW 0A
XORWF 12h,0
BTFSS 03,2
RETURN
CLRF 12h
INCF 13h,1
MOVLW 0A
XORWF 13h,0
BTFSS 03,2
RETURN
CLRF 13h
RETURN

MOVF 13h,0
CALL Table
MOVWF 06
CALL Display
CALL Clear
MOVF 12h,0
CALL Table
MOVWF 06
CALL Display
CALL Clear
MOVF 11h,0
CALL Table
MOVWF 06
CALL Display
CLRF 06
CALL Clear
CALL Clear
CALL Clear
GOTO MainP

END
;This is the start of memory for the program.
;Go to Bank 1
;Make all port B output
;Load W with 0000 0001
;Make RA0 input
;Go to Bank 0 - the program memory area.
;Clear portA
;Clear the button-press file
;Clear 'units' file
;Clear 'tens' file
;Clear 'hundreds' file


;Add W to the Program Counter to create a jump.
;0    format= gfedcba
;1    If any table value has a leading letter, it must be
;2    preceded with a "0."   E.g: 0A3h, 0FFh, 0CCh
;3
;4
;5
;6
;7
;8
;9



;Clear the display





;Test the input line on port A
;Button not pressed
;Button pressed first time?
;Button already pressed 
;Set button-press flag
;Button pressed. Increment count









;Increment units.
;Has count reached ten?
;Compare file 11h with ten
;Check the zero flag in Status file
;Count has not reached ten
;Zero the units file
;Increment tens.
;Has count reached ten?
;Compare file 12h with ten
;Check the zero flag in Status file
;Count has not reached ten
;Zero the tens file
;Increment hundreds.
;Has count reached ten?
;Compare file 13h with ten
;Check the zero flag in Status file
;Count has not reached ten
;Zero the hundreds


;Copy 'hundreds' into W

;Display the number


;Copy 'tens' into W

;Display the number


;Copy 'units' into W

;Display the number

;Blank the display




;Tells assembler end of program

 

 


 
Pulse

 
BTFSS 05,0

 
;Test RA0 for a LOW