PIC16F527 don't do nothing...


Closed Thread
Results 1 to 3 of 3
  1. #1

    Default PIC16F527 don't do nothing...

    After banging on this thing for a few hours I'm beginning to think this device is really chewing gum with metal legs. This is kindof' an odd device; its like a "PIC12Fxxx" but with a "PIC16Fxxx" designation, with built-in opamps (which is why I'm using it).

    I'm simply trying to blink an LED. The outputs, across the board, seem to be set as inputs. The first question I have is, how does one set the TRISA on 12 bit devices? If I give it a TRISA command I get an error. Data sheet isn't much help; it refers to "TRISA, TRISB, TRISC". Despite that, I don't think that's the problem given that my LED is on PORTC.0...

    As you can see in the code, PORTC.0 is an output, and I believe all the appropriate configuration bits are set properly. Comparators are off, A/D is off, OPAMPS are "on", ANSEL is configured. I know the part is running; I can see the clock out on the clock out pin (DIV/4). MCLR works as well. Just no output from anything. Can someone give this an eyeball and tell me what I've over-looked? Never had so much trouble with any device blinking an led...

    BTW: I'm using the latest PBPX 3.0.7.4 with a U2 programmer running meProg v.4.51.

    Thanks in advance,

    Mike T.

    Code:
    '****************************************************************
    '*  Name    : LED_000.BAS                                      *
    '****************************************************************
    #CONFIG
        __config _FOSC_INTRC_CLKOUT &_WDTE_OFF &_CP_OFF &_MCLRE_ON &_IOSCFS_4MHz &_CPSW_OFF &_BOREN_OFF &_DRTEN_OFF
    #ENDCONFIG
    
    DEFINE  OSC 4
    
    INCLUDE "modedefs.bas"
    
    
    ;ALIASES
    PBTN    VAR PORTA.0         ; INPUT - DIGITAL
    ; NOT USED  VAR PORTA.1     ; OUTPUT - SET LOW
    ANIN2   VAR PORTA.2         ; INPUT - ANALOG
    ; NOT USED  VAR PORTA.3     ; OUTPUT - SET LOW
    ANIN3   VAR PORTA.4         ; INPUT - ANALOG
    OLED    VAR PORTA.5         ; OUTPUT - DIGITAL
    
    ; OP2_MINUS  VAR PORTB.4    ; INPUT - OPAMP
    ; OP2_PLUS   VAR PORTB.5    ; OUTPUT - OPAMP
    ; NOT USED   VAR PORTB.6    ; OUTPUT - DIGITAL
    ; NOT USED   VAR PORTB.7    ; OUTPUT - DIGITAL
    
    LED    VAR PORTC.0          ; OUTPUT - DIGITAL
    ; NOT USED   VAR PORTC.1    ; OUTPUT - DIGITAL
    ; OP2_OUT   VAR PORTC.2     ; OUTPUT - ANALOG
    ; OP1_OUT    VAR PORTC.3    ; OUTPUT - ANALOG
    ; NOT USED    VAR PORTC.4   ; OUTPUT - DIGITAL
    ; NOT USED   VAR PORTC.5    ; OUTPUT - DIGITAL
    ; OP1_MINUS   VAR PORTC.6   ; INPUT - ANALOG
    ; OP1_PLUS    VAR PORTC.7   ; INPUT - ANALOG
    
    
    ;PORT CONTROL REGISTERS
    ;PORTA
    ;TRISA   =   %00010101	    ;HUH??????    
    
    TRISB   =   %00010000
    
    TRISC   =   %11000000
    
    ; ANSEL
    ;   7      6       5       4       3       2       1       0
    ;RC.3   RC.2    RC.1    RC.0    RA.4    RA.2    RA.1    RA.0
    ANSEL =    %11001100         
    
    ; INTCON CONTROL REGISTERS
    INTCON0 =   %00000000
    INTCON1 =   %00000000   
    
    ; OPTION CONTROL REGISTER
    OPTION_REG  =   %11000000
    
    
    ;ADC CONTROL REGISTERS       
    ADCON0 =    %00000000       ; ADC DISABLED 
    
    ; COMPARATOR CONTROL REGISTERS
    CM1CON0 =   %01000000        ; COMPARATORS OFF - BIT 3
    CM2CON0 =   %01000000
    VRCON.7   = 0                ; VOLTAGE REFERENCE OFF
    
    ; OPAMP CONTROL REGISTER
    OPACON  =   %00000011       ; OPAMPS ON
    
    
    BLINK:
        HIGH    LED
        PAUSE   500
        LOW     LED
        PAUSE   500
        GOTO    BLINK
        
        
        
        end

  2. #2
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,597


    Did you find this post helpful? Yes | No

    Default Re: PIC16F527 don't do nothing...

    I use this order, might not make a difference but I like structure (old mainframe programer):

    Configs
    DEFINES
    Special registers
    TRIS
    Ports
    Variables

    Robert

  3. #3


    Did you find this post helpful? Yes | No

    Default Re: PIC16F527 don't do nothing...

    I'm posting a follow-up to this in case it may help someone else. Though I'm really not happy with this device (the clock jitter in INTOSC mode is too severe for my tastes) here's what I've found out. It appears that BANKSEL does not work on this device. Not sure why; I've reported it to the guys at meLabs and I'm sure they'll get to the bottom of it. In the meantime, assembly to the rescue. If you are not aware of it, there are two things I got from this exercise:

    1.) A friend had to remind me that going back to the early days of the '54, there wasn't a TRIS register; there was a TRIS command. This device, being part of the 12-bit core series, uses the TRIS command. So, you load "W" with the value you want TRIS to be, and then use the TRIS command to set the I/O. No big deal, as long as you're aware of it. You can see it in the code.

    2.) BANKSEL doesn't work (nor does BSR). There is in fact, yet again, a command for this: MOVLB - move literal to BSR.

    Once past those two things, things started looking up (the attached code compiles and runs fine). One thing to keep in mind, generally speaking with any of the devices that have alternate functions on a pin (in other words, all PIC's); set these functions prior to setting TRIS, otherwise these functions will trample on TRIS. Or bit select them, however you like to code. I'm spoiled by the PIC16F1xxx series, and if it wasn't for the fact that these "smaller" devices are so cheap, would use them for everything.

    Code:
    '****************************************************************
    '*  Name    : LED_003.BAS                                      *
    '****************************************************************
    ;#CONFIG
    ;    __config _FOSC_INTRC_CLKOUT &_WDTE_OFF &_CP_OFF &_MCLRE_ON &_IOSCFS_8MHz &_CPSW_OFF &_BOREN_ON &_DRTEN_OFF
    ;#ENDCONFIG
    
    DEFINE  OSC 8
    
    
    ;ALIASES
    
    
    LED    VAR PORTC.0          ; OUTPUT - DIGITAL
    
    
    ;PORT CONTROL REGISTERS
     
        asm
        MOVLB   b'00000000'     ; SELECT BANK 0
        
        MOVLW   b'00000000'	       
        MOVWF   ADCON0
    
        MOVLW   b'00000000'	       
        MOVWF   INTCON0
    
        MOVLW   b'00000000'	       
        MOVWF   INTCON1
    
        MOVLB   b'00000001'     ; SELECT BANK 1
    
        MOVLW   b'00000000'	       
        MOVWF   CM1CON0
    
        MOVLW   b'00000000'	       
        MOVWF   CM2CON0
    
        MOVLW   b'00000000'	       
        MOVWF   VRCON
        
        MOVLB   b'00000010'     ; SELECT BANK 2
    
        MOVLW   b'00000000'	       
        MOVWF   ADCON0
        
        MOVLW   b'00000000'	       
        MOVWF   INTCON0
        
        MOVLW   b'00000000'	       
        MOVWF   INTCON1
        
        MOVLB   b'00000011'     ; SELECT BANK 3
    
        MOVLW   b'00000011'	       
        MOVWF   OPACON        
    
        MOVLW   b'11001101'
        MOVWF   ANSEL
        
        MOVLB   b'00000000'
        
        MOVLW   b'00010101'	    ; LOAD W    
        TRIS    06h             ; LOAD TRIS PORTA 
    
        MOVLW   b'00010000'	    ; TRIS  PORTB   
        TRIS    07h
        
        MOVLW   b'11000000'	       
        TRIS    08h    
        endasm
    
    
        low led
     
    
    MAIN:
        HIGH    led    
        pause   250
        low     led
        pause   250
        goto    main
        
        
        end

Members who have read this thread : 1

You do not have permission to view the list of names.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts