GPIO not responding to movwf PIC12F675

Thread Starter

AngryGecko

Joined Jul 7, 2017
44
I'm new to assembly language on pic microcontrollers and am just trying to control an IO port via GPIO as the datasheet says. Here is my code:

;---------------------------------------------------------------------------------------------------------------------------------------------------------------
INCLUDE <p12f675.inc>

__CONFIG _INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_OFF & _MCLRE_ON & _BOREN_ON & _CP_OFF & _CPD_OFF

RES_VECT CODE 0x0000
GOTO START

MAIN_PROG CODE

START
bsf STATUS, 5
clrw
movwf TRISIO
bcf STATUS, 5

movlw b'00000100'
movwf GPIO
movlw b'00000000'
movwf GPIO

END
;------------------------------------------------------------------------------------------------------------------------------------------------------------------

When I try to simulate this in MPLAB while incrementing the program counter by hand, I can see that WREG gets loaded correctly to '00000100'. On the next instruction GPIO should be loaded from WREG but it stays at 0x08. Am I missing something here or is something wrong with the simulator? Thanks in advance!
 

AlbertHall

Joined Jun 4, 2014
12,345
You need to clear ANSEL (set the gpio to digital) and load CMCON with 0x07 (disable the comparators).
From the datasheet:
Note:
The ANSEL (9Fh) and CMCON (19h)
registers (9Fh) must be initialized to
configure an analog channel as a digital
input. Pins configured as analog inputs will
read ‘0’. The ANSEL register is defined for
the PIC12F675.
 

Thread Starter

AngryGecko

Joined Jul 7, 2017
44
Thank you!!! Now it works
You need to clear ANSEL (set the gpio to digital) and load CMCON with 0x07 (disable the comparators).
From the datasheet:
Note:
The ANSEL (9Fh) and CMCON (19h)
registers (9Fh) must be initialized to
configure an analog channel as a digital
input. Pins configured as analog inputs will
read ‘0’. The ANSEL register is defined for
the PIC12F675.
 

MaxHeadRoom

Joined Jul 18, 2013
28,619
Look at some of the free tutoriols for pic's starting with the 12f series, such as an Australian one that has many, search Gooligum tutorials.
Max.
 
Top