![]() |
![]() |
![]() |
|
|
|||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
|
|
Thread Tools | Display Modes |
|
|
(permalink) |
|
Hi all,
I am testing the 12F629 found something very weird. The PIC is suppose to flash two LEDs on GP0 and GP1. 1. The movlw b'00001111' to set TRISIO is not a typo - bit 0 and bit 1 are supposed to be zero for output, but LEDs won't flash unless I set them to one! :shock: I ran the MPLAB simulator, and: 2. bsf GPIO, GP1 will set GP1 bit to zero! :? 3. bcf GPIO, GP0 will set GP0 bit to one! :roll: Anyone has any idea what's going on? Here is the code: Code:
org 0x00 goto init init bcf STATUS, RP0 ; Bank 0 clrf GPIO ; Init GPIO movlw 07h ; Set GP<2:0> movwf CMCON ; digital IO. Turn off comparator movlw b'00001111' ; GP<1:0> output GP<3:2> inputs movwf TRISIO ; bsf STATUS, RP0 ; Bank 1 main bsf GPIO, GP1 bcf GPIO, GP0 call delay bcf GPIO, GP1 bsf GPIO, GP0 call delay goto main delay ;;;;; delay routine ;;;;;; |
|
|
|
|
|
|
(permalink) |
|
Without checking the datasheet, but based on other PIC's, the bank switching looks incorrent. TRIS is usually in bank 1, and GPIO in bank 0, you have them the other way. Which is why you think setting TRIS to 1 is making them an output - it's not, it's setting GPIO high. Then in the main part of the program you're toggling the TRIS bits, switching them from inputs to outputs.
|
|
|
|
|
|
|
(permalink) |
|
yeah i just checked with the data sheet, GPIO is in bank 0, not bank 1. TRISIO is in bank 1.
__________________
www.winpicprog.co.uk - Great PIC language tutorials. |
|
|
|
|
|
|
(permalink) |
|
Everything works now! Thanks a lot guys!
|
|
|
|
|