;********************************************************************** ; This file is a basic code template for assembly code generation * ; on the PICmicro PIC16F84. This file contains the basic code * ; building blocks to build upon. * ; * ; If interrupts are not used all code presented between the ORG * ; 0x004 directive and the label main can be removed. In addition * ; the variable assignments for 'w_temp' and 'status_temp' can * ; be removed. * ; * ; Refer to the MPASM User's Guide for additional information on * ; features of the assembler (Document DS33014). * ; * ; Refer to the respective PICmicro data sheet for additional * ; information on the instruction set. * ; * ; Template file assembled with MPLAB V3.99.18 and MPASM V2.15.06. * ; * ;********************************************************************** ; * ; Filename: ustr.asm * ; Date: 3/7/99 * ; File Version: 1.0 * ; * ; Author: Mike DeMetz * ; Company: MDD Hobbytronics * ; * ; * ;********************************************************************** ; * ; Files required: * ; * ; * ; * ;********************************************************************** ; * ; Notes: * ;Based on 8051 code by Wagner Lipnharski * ; LCD Pinout: * ; ________________ * ;| __________ _| +5V * ;| | | Clk* * ;| |__________| _ Gnd * ;|________________| Data * ; Front View * ;Works even with 50-100K in series with pins(even Gnd). * ;With .1uF across power, will work off power from Clk and Data * ;(feeds back and cahrges cap)even with 50K resistors. * ; * ;********************************************************************** list p=16F84 ; list directive to define processor #include ; processor specific variable definitions errorlevel -302 ; suppress message 302 from list file __CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _XT_OSC ; '__CONFIG' directive is used to embed configuration data within .asm file. ; The lables following the directive are located in the respective .inc file. ; See respective data sheet for additional information on configuration word. ;***** VARIABLE DEFINITIONS ;w_temp EQU 0x0C ; variable used for context saving ;status_temp EQU 0x0D ; variable used for context saving ; Sbyte equ H'0E' Sbits equ H'0F' Schar equ H'10' ;DiGits are BCD 0-9, Hex(7 seg) 0-F, Special H'10','11','12',anything else=crash DG equ H'11' DG1 equ DG+0 ;LCD digit 1 (Left) DG2 equ DG+1 DG3 equ DG+2 DG4 equ DG+3 DG5 equ DG+4 ;LCD digit 5 (Right) #define Data 0 ;Bit 0 of Portx #define Clk 1 ;Bit 1 #define Blnk H'10' #define Dash H'11' #define Cur H'12' ;********************************************************************** ORG 0x000 ; processor reset vector goto main ; go to beginning of program ; ORG 0x004 ; interrupt vector location ; movwf w_temp ; save off current W register contents ; movf STATUS,w ; move status register into W register ; movwf status_temp ; save off contents of STATUS register ; isr code can go here or be located as a call subroutine elsewhere ; movf status_temp,w ; retrieve copy of STATUS register ; movwf STATUS ; restore pre-isr STATUS register contents ; swapf w_temp,f ; swapf w_temp,w ; restore pre-isr W register contents ; retfie ; return from interrupt main bsf STATUS,RP0 ; set file register bank to 1 movlw b'00000000' ;PortA all out (SIMMSTICK) movwf TRISA movlw b'0000000' ;All out on PortB Movwf TRISB bcf STATUS,RP0 ; set file register bank to 0 ; remaining code goes here ;First send the top 4 segments for all 5 digits ;Right to Left show movlw D'5' movwf Schar ;5 digits movlw DG5 ;DiGit #5 movwf FSR show10 movf INDF,W ;Get DiGit call Getchar ;get segment image call dtop decf FSR,F ;Point to next DIGit decfsz Schar,F ;Do it 5 times goto show10 ;Then send lower 3 segments for all 5 ;Left to Right movlw D'5' movwf Schar ;5 digits movlw DG1 ;DiG it #1 movwf FSR show11 movf INDF,W ;Get DiGit call Getchar ;get segment image call dbot incf FSR,F ;point to next DIGit decfsz Schar,F ;Do it 5 times goto show11 return ;Shift Byte from table 4 bits to left for top for segments dtop movwf Sbyte ; Byte digit image movlw D'4' ; set the bit counter movwf Sbits ; dtop1 rlf Sbyte,F ; btfsc STATUS,C ; the bit is a ... goto shi ; 1, branch bcf PORTB,Data ; 0, send low goto sclk shi bsf PORTB,Data ; 1, send high nop sclk call clkit decfsz Sbits,F ; do all 4 bits goto dtop1 return ;Shift Byte from table 3 bits to right for lower 3 segments dbot movwf Sbyte ; Byte digit image movlw D'3' ; set the bit counter movwf Sbits ; dbot1 rrf Sbyte,F ; btfsc STATUS,C ; the bit is a ... goto shi1 ; 1, branch bcf PORTB,Data ; 0, send low goto sclk1 shi1 bsf PORTB,Data ; 1, send high nop sclk1 call clkit decfsz Sbits,F ; do all 3 bits goto dbot1 return ; clkit nop ;Data settle bcf PORTB,Clk ;Clk data nop nop bsf PORTB,Clk return ; Getchar addwf PCL,F ;W contains H'00-12' retlw H'E7' ;Digit 0 retlw H'84' ;Digit 1 retlw H'D3' ;Digit 2 retlw H'D6' ;Digit 3 retlw H'B4' ;Digit 4 retlw H'76' ;Digit 5 retlw H'77' ;Digit 6 retlw H'C4' ;Digit 7 retlw H'F7' ;Digit 8 retlw H'F6' ;Digit 9 retlw H'F5' ;Char A retlw H'37' ;Char b retlw H'63' ;Char C retlw H'97' ;Char d retlw H'73' ;Char E retlw H'71' ;Char F retlw H'00' ;Blank (Hex 10) retlw H'10' ;Dash - (Hex 11) retlw H'02' ;Cursor _ (Hex 12) ; ; Digit 7 Segment mapping ; ; _F_ ; E| |G ; |_D_| ; | | ; C|___|A ; B ;Digit "7" Hex H'C4 Bin: B'1100 0100 ; Segments : GFED -ABC ;Digit "4" Hex H'B4 Bin: B'1011 0100 ; Segments : GFED -ABC ; :For upside down display Digits arranged 5 4 3 2 1 ; _B_ ; A| |C ; |_ _| ; | D | ; G|___|E ; F END ; directive 'end of program'