PIC assembly code doesn't chang ports ?

Hi all,

I'm trying some assembly code for the PIC18F1320. I've always used C but the new job has some projects in assembly code for the cheap PICs (PIC12F508 and

509) and I'm required to be able to modify them. YEACH!. So ... I have some of these PICs and I'm playing with the stuff. Anyhow ... I'm using the ICD2 and MPLAB 7.4 to write the assy code. It compiles with no errors or warnings. I'm using the debugger to watch the port pins (PortA and PortB pins 0) toggle but no luck. Here is the code:

movlw 0x70 ;Internal Oscillator, 31kHz movwf OSCCON ;

movlw 0 ;set portA for output

Reply to
Rodo
Loading thread data ...

You need to configure the pins as digital I/O. That is your immediate problem. See datasheet table 10-2.. in particular ADCON1 which causes the port pins to power up in analog mode.

Also, you should (almost) always use the LATx register rather than the PORTx register.

Best regards, Spehro Pefhany

--
"it\'s the network..."                          "The Journey is the reward"
speff@interlog.com             Info for manufacturers: http://www.trexon.com
 Click to see the full signature
Reply to
Spehro Pefhany

For the low end micros, you need to perform bank switching when you are configuring the port (Bank 1) and then writing to it (Bank 0). I don't think this applies to the 18F parts (I use 18F242), but is probably needed for the 12F508 and 12F509. The MPLAB assembler will usually give a warning for addresses not in Bank 0, but there is a directive to turn off that warning.

The LATx register is usually best for bit set and reset operations, which use a Read-Modify-Write on the entire port. If you are writing data to the entire port, it is not really necessary. Sometimes it is good to read the port after writing to it to make sure the outputs have changed. If there is a large capacitive load, it may take a while.

Paul

Reply to
Paul E. Schoen

What fun, I remember having these probs in the early 1980's. experience is a wonderful thing.

Reply to
Marra

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.