pic12f683 push button problem

Thread Starter

le2dangerous

Joined Jan 11, 2020
12
Now how do i change GP4 to a input pin with TRISIO = 0x02;.
thanks again for the help, also how can i learn what 0x02 is and how it associate GP0 GP1 as out and in?
thansk
 

AlbertHall

Joined Jun 4, 2014
12,625
You need a resistor in series with the LED, perhaps 470Ω, to avoid the read-modify-write problem and a pull down resistor for GP1, perhaps 10k.
 

AlbertHall

Joined Jun 4, 2014
12,625
Now how do i change GP4 to a input pin with TRISIO = 0x02;.
thanks again for the help, also how can i learn what 0x02 is and how it associate GP0 GP1 as out and in?
thansk
Consider the value in binary. 0x02 is binary 00000010. Each binary bit represents an IO pin, LSB is GP0 then going in sequence.
 

jpanhalt

Joined Jan 18, 2008
11,087
As I commented earlier (post #2), I am not sure how the compiler works. Addressing the individual pins can be a little confusing in these devices. If you want GP4 it is bit #4 in a 6-bit register. The upper two bits of the register are not read:
1578826822698.png

The hex value would be 0x10. If you want GP2 (see your post #22), then the hex value is 0x04.(see edit) I find it convenient and a little more obvious to use the binary representation, e.g., b'00010000' for GP4, when referencing GPIO pins.

EDIT: I am a victim of using binary and being half asleep. From the include file,
1578828209668.png
The default radix of the chip is hex, so GP4 = GPIO,4
 
Last edited:
Top