Jag har byggt ett litet prov projekt i syftet att lära mig. Projektet är uppbyggt av en PIC16f877a, några lysdioder och en 3-siffrig 7-segments LED display (gemensam cathode). Jag har fått den att vissa fasta siffror dvs t.ex. 001, men vill nu kunna räkna upp. För tillfället använder jag bara en siffra av de tre multiplexade displayerna, det finns inte heller någon kod till de andra lysdioderna här.
Kod: Markera allt
list p=16f877A ; list directive to define processor
#include <p16f877A.inc> ; processor specific variable definitions
__CONFIG _XT_OSC & _WDT_OFF & _LVP_OFF & _PWRTE_ON
; '__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.
cblock h'20'
d1
d2
d3
d4
unit
endc
org 0
Start:
clrf PORTA ; Make all ports output
clrf PORTB
bsf STATUS,RP0 ; Go to bank 1
clrf TRISA
clrf TRISB
bcf STATUS,RP0 ; Back to bank 0
movlw 0x08
movwf d2
movlw 0x2F
movwf d3
movlw 0x03
movwf d4
movlw 0x04
movwf PORTA ; Endast sista siffran ska lysa!
Main
call Table
movwf PORTB
call Delay2
goto Main
Table
addwf PCL
retlw 0x3f ;0
retlw 0x06 ;1
retlw 0x5B ;2
retlw 0x4F ;3
retlw 0x66 ;4
retlw 0x6D ;5
retlw 0x7C ;6
retlw 0x07 ;7
retlw 0x7F ;8
retlw 0x67 ;9
Delay2
decfsz d2, f
goto $+2
decfsz d3, f
goto $+2
decfsz d4, f
goto Delay2
;3 cycles
goto $+1
nop
return
END ; directive 'end of program'
Jag är nybörjare inom programering av uC och detta är första gången jag håller på med data tables.
Min hjälp hittilst har varit:
http://www.picaxeforum.co.uk/archive/in ... -2317.html
http://www.mstracey.btinternet.co.uk/pi ... gtut10.htm