We will use PIC pins RA0 to RA7 to interface to the the a-g,dp segments. At the start of your programs, include the following code that will set PORTA pins RA0-RA7 to output ~0V or ~5V:
SetOut Bank1 ;select data direction register page clrf TRISA ;set all PORTA pins to output ;a voltage on RA0-RA7 Bank0 ;back to user memory pageTo begin, flash the display segment 'a' as previously done with the LED connected to the PIC RC0 pin:
To estimate the maximum current drawn by the 7-segment display:
Connect, using resistors and jumpers, the remaining segments of Digit2 to PORTA:
SetBits movlw pattern ;user sets pattern of bits to turn on movwf PORTA ;output 8-bit pattern on RA0-RA7Tabulate and test bit patterns that display the numbers 0-9,A-F.
You can include a table of these patterns into a subroutine. By placing a number 0-15 into W and calling the subroutine, W will be loaded with the 7-segment pattern for that number.
Binary numbers are preceded with a '%' sign.
The brw instruction adds the content of W to the program counter (PC) to skip past 0 or more instructions, in this case to index into a table of values.
The retlw instruction loads W with the given constant and returns from the subroutine to execute the instruction that follows 'call Bin2LED'.
The andlw instruction clears the upper nibble of W, preventing it from indexing past the size of the table and crashing the program, in case the user enters an invalid number. For this to work, the table must then include sixteen (or more) retlw instructions.
Seconds is an 8-bit register that contains a value Seconds[7:0]=0-59, updated every second by a PIC resident real-time clock.
WH, WL are registers consisting of bits WH[7:0], WL[7:0] in data memory, typically used to store the result of a subroutine call.
The subroutine W2BCD converts the value in W to three binary coded decimal (BCD) digits, the hundreds value (0-2) in WH bits 4 to 7, WH[7:4], tens (0-9) in WH[3:0] and ones (0-9) in WL[3:0]. In converting Seconds, WH[7:4]=0, WH[3:0]=tens, WL[7:4]=0, WL[3:0]=ones.
Edit your multiplex code as shown. Note the '*' tagged instructions. Your dual display should increment each second, then at 59 advance to 0. What instruction would you add at the start of the program to reset Seconds so that the count begins at zero?
Comment out the call Bin2LED instructions. What is displayed?