Hello folks,
I'm writing a simple program for the 16f84 pic to learn how it works. I would like to simulate a switchbutton on pin RA0, that when pressed, causes an internal counter to decrement. My problem seems to be when I try to turn on the bits on PORTA RA0 to simulate the pin going high, it never gets done.
I am using the gpasm assembler version 0.10.0 and the gpsim simulator version 0.21.1
Here is the program
include p16f84.inc list p=16f84 radix hex __fuses _CP_OFF & _WDT_OFF
org 0x00 goto init
cblock 0x0c tmp endc
init bsf STATUS,RP0 ;select bank 1 movlw 0x01 ;set PORTA RA0 pin to input movwf TRISA bcf STATUS,RP0 ;select bank 0
movlw 0x10 ;set counter to 10 movwf tmp bsf PORTA,0 ;simulate input on port RA0 ;this is where I believe I'm ;having probelms
main btfsc PORTA,0 decfsz tmp,1 ;countdown from 20 ;this never gets executed as PORTA bit 0 is ;always zero goto main end
Here is the snippet of my session with the debugger. The important part is:
gpsim> 0x0000000000000008 p16f84 0x0007 0x1405 bsf porta,0 read: 0x00 from porta wrote: 0x00 to porta
According to the debugger, PORTA never gets bit 0 set to 1. Am I perhaps missing something, or do I misunderstand how this works. If I want to configure a pin as an input I should turn on the appropriate bits in TRISA and set them to 1, no?
I have read the faq and looked at other peoples code, and they seem to be doing the same thing I am. So what am I missing?
The entire debugging sessiong step by step is included below in case any of it is relevant.
Thanks!
Found pic16f84 f84 construct TMRO::start Cycle break point was ignored because cycle 0 has already gone by current cycle is 0 Hex file "tmp.hex"
** SETTING CONFIG address = 0x2007 value = 0x3ffb --- Reset gpsim> 0x0000000000000001 p16f84 0x0000 0x2801 goto 0x0001 gpsim> 0x0000000000000002 p16f84 0x0001 0x1683 bsf status,5 read: 0x18 from status wrote: 0x38 to status gpsim> 0x0000000000000003 p16f84 0x0002 0x3001 movlw 0x01 wrote: 0x01 to W gpsim> 0x0000000000000004 p16f84 0x0003 0x0085 movwf porta read: 0x01 from W wrote: 0x00 to porta wrote: 0x01 to trisa gpsim> 0x0000000000000005 p16f84 0x0004 0x1283 bcf status,5 read: 0x38 from status wrote: 0x18 to status gpsim> 0x0000000000000006 p16f84 0x0005 0x3010 movlw 0x10 wrote: 0x10 to W gpsim> 0x0000000000000007 p16f84 0x0006 0x008C movwf 0x0c read: 0x10 from W wrote: 0x10 to 0x0c gpsim> 0x0000000000000008 p16f84 0x0007 0x1405 bsf porta,0 read: 0x00 from porta wrote: 0x00 to porta gpsim> 0x0000000000000009 p16f84 0x0008 0x1805 btfsc porta,0 read: 0x00 from porta skipped: 000a goto 0x0008 gpsim> 0x000000000000000B p16f84 0x000A 0x2808 goto 0x0008 gpsim> 0x000000000000000D p16f84 0x0008 0x1805 btfsc porta,0 read: 0x00 from porta skipped: 000a goto 0x0008 gpsim> 0x000000000000000F p16f84 0x000A 0x2808 goto 0x0008 gpsim> 0x0000000000000011 p16f84 0x0008 0x1805 btfsc porta,0 read: 0x00 from porta skipped: 000a goto 0x0008