1. peter_morley

    Thread Starter Member

    Mar 12, 2011
    179
    0
    Hi I've been asking a lot of questions lately so try to bear with me. I am trying to configure GPIO 0,1 and 2 to be digital outputs. I can get GPIO 0 and 1 to send me a logic of 5V but when I call the setGP2 function I don't get a high output on GPIO 2. My TRISIO register is set up as B'00001000' and cleared ANSEL so all of them would be digital outputs except GPIO 3 being always a input. Do I also have to alter the CMCON? What do the bits signify it doesn't really say much in the datasheet. Here is my code:
    Code ( (Unknown Language)):
    1.  
    2. list      p=12f675            ; list directive to define processor
    3. #include <p12f675.inc>        ; processor specific variable definitions
    4.  
    5.     __CONFIG   _CP_OFF & _CPD_OFF & _BODEN_OFF & _MCLRE_OFF & _WDT_OFF & _PWRTE_ON & _INTRC_OSC_NOCLKOUT  
    6.  
    7. ;*************************** DEFINE STATEMENTS ********************************
    8.  
    9. ; Register Bank Directories
    10.  
    11. #define Bank0   banksel 0x00        ; first registerr bank = Bank 0
    12. #define Bank1   banksel 0x80        ;second register bank = Bank 1
    13.  
    14. #define Blank       B'00000000'     ; All LEDs off
    15. #define ConfigTRI   B'00001000'     ; Configure I/O
    16. ;#define Counter        0FFh            ; hex vale xFF
    17.  
    18. ;****************************** Start of Program ******************************
    19.     org     0x000           ; processor reset vector
    20.     goto    Initialize
    21.  
    22. ;******************************************************************************
    23. ; Initialize
    24. ;   Initialize Special Function Registers    
    25. ;******************************************************************************
    26.     org 0x005           ; Start of Programm Memory Vector
    27. Initialize
    28.  
    29.     Bank1               ;Bank 1
    30.     clrw               
    31.     clrf ANSEL          ;Digital I/O   
    32.     movlw ConfigTRI     ;Set GP5,4,2,1, and 0 as outputs
    33.     movwf TRISIO        ;and set GP3 as singular input
    34.     Bank0               ;Bank 0
    35.     clrw
    36.     clrf GPIO           ;Init GPIO
    37.     movlw 07h           ;GPIO as all digital
    38.     movwf CMCON         ;digital IO
    39.     ;clrw
    40.     ;movlw Counter
    41.  
    42. Main
    43.     ;call setGP0
    44.     ;call setGP1
    45.     call setGP2
    46.     ;call clearGP
    47.     goto Main
    48.  
    49. clearGP
    50.     movlw   Blank           ; clears pins of GPIO
    51.     movwf   GPIO            ; move value in w to register GPIO
    52.     return
    53.    
    54. setGP0                     
    55.     movlw   B'00000001'     ; set GPIO 0
    56.     movwf   GPIO            ; move value in w to register GPIO
    57.     return 
    58. setGP1
    59.     movlw   B'00000010'     ; set GPIO 1
    60.     movwf   GPIO            ; move value in w to register GPIO
    61.     return     
    62. setGP2
    63.     movlw   B'00000100'     ; set GPIO 2
    64.     movfw   GPIO            ; move value in w to register GPIO
    65.     return
    66.  
    67. end
     
  2. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    You've put movfw instead of movwf.
    movfw var is a pseudo-operation for movf var, W
     
    peter_morley likes this.
  3. peter_morley

    Thread Starter Member

    Mar 12, 2011
    179
    0
    Thanks Mark! Maybe someday I will know what I am doing...
     
Loading...