Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Need help on porting code from 16c71 to 16f628a

Status
Not open for further replies.

johnnyquest

New Member
I asm using Proteus to simulate microchips application note AN557 page 2 MULTIPLEXING FOUR 7-SEGMENT LEDS WITH A 4X4 KEYPAD. I changed the code to work on a 16f64 by commenting out "movlw 3" "movwf ADCON1 " and it works for the most part. When trying to port the code to a 16f628a I changed to general purpose addresses to start at 0x20 and commented out "bcf STATUS,RP1" "movlw 3" "movwf ADCON1 " from InitPorts and added "movlw 0x07" and "movwf COMCON" to the beggining of InitPorts. When trying to simulate this in Proteus the LEDs work but only to keys work and they are not saved in thier positions; MSD LSD etc.
Am I looking over something. Please help point me in the right direction. Thanks
 
Update:
I set a breakpoint in the subroutine ScanNext at "btfsc KeyFlag,keyhit" in the Proteus simulation that works, when a key was pressed it broke at that point. When I set up the same for the 16f628a model it is not breaking during a keypress. Would have to change some code using INTCON, RBIE on the 16f628a or is the simuator flawed?

ScanNext
movf PORTB,W ;read to init port
bcf INTCON,RBIF ;clr flag
rrf TempD, F ;get correct column
btfss STATUS,C ;if carry set?
goto NoKey ;no then end
movf TempD,W ;else output
movwf PORTB ;low column scan line
nop
btfss INTCON,RBIF ;flag set?
goto ScanNext ;no then next
btfsc KeyFlag,keyhit ;last key released?
goto SKreturn ;no then exit
bsf KeyFlag,keyhit ;set new key hit
swapf PORTB,W ;read port
movwf TempE ;save in TempE
call GetKeyValue ;get key value 0 - F
movwf NewKey ;save as New key
bsf KeyFlag,ServKey ;set service flag
bsf KeyFlag,DebnceOn ;set flag
movlw 4
movwf Debnce ;load debounce time
SKreturn
call RestorePorts ;restore ports
return
 
I found the problem. I lowered the frequency to 100KHz on the pic and added delay loops to the keypad scan routine so that it could catch the low-high transition when a key is pressed. The breakpoint now goes on when a key is pressed. So I looked back through the code and increased the TMR0 interrupt so it would go off more. My question now is would the original code work in a real pic or is the Proteus VSM the problem? As I am just starting to learn how to program pics this week it would help me if someone could look at the code below and let me know if the timing is realistic for this keypad led application. Thanks

;The clock speed is 4.096Mhz. Dividing internal clk. by a 32 prescaler,
;the rtcc will be incremented every 31.25uS. If rtcc is preloaded
;with 96, it will take (256-96)*31.25uS to overflow i.e. 5mS. So the
;end result is that we get a rtcc interrupt every 5mS.
InitTimers
clrf MsdTime ;clr timers
clrf LsdTime ; /
clrf KeyFlag ;clr all flags
bsf STATUS,RP0 ;select pg 1
movlw B'10000100' ;assign ps to rtcc
movwf OptionReg ;ps = 32
bcf STATUS,RP0 ;select pg 0
movlw B'00100000' ;enable rtcc interrupt
movwf INTCON ;
movlw .96 ;preload rtcc
movwf TMR0 ;start counter
retfie
;
ServiceInterrupts
btfsc INTCON,T0IF ;rtcc interrupt?
goto ServiceTMR0 ;yes then service
clrf INTCON ;else clr all int
bsf INTCON,T0IE
return
;
ServiceTMR0
movlw .96 ;initialize rtcc HAD TO CHANGE THIS TO 200
;TO GET IT TO WORK IN THE SIMULATION

movwf TMR0
bcf INTCON,T0IF ;clr int flag
btfsc PORTA,0 ;if msb on then do
call ScanKeys ;do a quick key scan
call UpdateDisplay ;update display
return
;
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top