What is the minimal setup for PIC16F88

Discussion in 'Embedded Systems and Microcontrollers' started by NomadAU, Feb 13, 2014.

  1. NomadAU

    Thread Starter Member

    Jul 21, 2012
    32
    0
    Hi,

    I'm trying to debug a problem with USART on this chip. I'm familiar with using the PIC 16F628 but new to the 16F88 and am finding it a bit of a challenge to configure (particularly the clock).

    I suspect my USART problem (erratic behaviour, data duplication, data sometimes not received) is due to an inaccurate clock on the mcu side, so I am going back to basics in order to get the clock configuration correct.

    I have stripped everything from my breadboard and just connected the Vss and Vdd, and a resistor/LED to RB7.

    Using the following program from an online source, I am expecting the LED to blink when connected to any of the digital pins. However, I get no output at all from the LED. As sometimes happens, right now it feels like I am going backwards instead of making progress with this project...

    Question: Are there any ESSENTIAL connections other than Vss/Vdd and the output LED pin that I need? I assume MCLR is not in use so no need to tie this to ground.

    Code ( (Unknown Language)):
    1.  
    2. ;***************************************************************
    3.     title    "PIC Sample code: PIC16F88 program"
    4.     subtitle    "Version 1.1 (c) Jay.slovak"
    5. ;Designed for 16F88 @4Mhz
    6. ;***************************************************************
    7.     list    p=16F88
    8.  #include "p16f88.inc"  ; PIC definitions
    9.     __CONFIG    _CONFIG1, _CP_OFF & _CCP1_RB0 & _DEBUG_OFF & _WRT_PROTECT_OFF & _CPD_OFF & _LVP_OFF & _BODEN_OFF & _MCLR_ON & _PWRTE_ON & _WDT_OFF & _INTRC_IO
    10.     ERRORLEVEL -302
    11. ;***************************************************************
    12. z1    equ    20h
    13. z2    equ    21h
    14. z3    equ    22h
    15. z4    equ    23h
    16. ;***************************************************************
    17.     org    0x0000
    18.     goto    INIT
    19.     NOP
    20.     NOP
    21.     NOP
    22.     NOP
    23.     org    0x0005
    24. INIT
    25.     CLRF    PORTA
    26.     CLRF    PORTB
    27.     BSF    STATUS,RP0    ;Select Bank 1
    28.     CLRF    ANSEL    ;All pins are Digital
    29.     BSF    OSCCON,6    ;Set oscilator to 4Mhz
    30.     BSF    OSCCON,5
    31.     MOVLW    H'07'
    32.     MOVWF    CMCON    ;Turn off comparators
    33.     CLRF    TRISA    ;Port A is output
    34.     CLRF    TRISB    ;Port B is output
    35.     BCF    STATUS,RP0    ;Select Bank 0
    36.  
    37. Start
    38.     MOVLW    0xFF
    39.     MOVWF    PORTA
    40.     MOVWF    PORTB
    41.     ;goto    $
    42.     CALL    Delay
    43.     CLRF    PORTA
    44.     CLRF    PORTB
    45.     CALL    Delay
    46.     GOTO    Start
    47. ;***************************************************************
    48. ;***************************************************************
    49.     subtitle    "Delay subprogram"
    50. Delay    movlw    D'3'
    51.     movwf    z3
    52.     movlw    D'137'
    53.     movwf    z2
    54.     decfsz    z1,f
    55.     goto    $-1
    56.     decfsz    z2,f
    57.     goto    $-3
    58.     decfsz    z3,f
    59.     goto    $-5
    60.     return
    61.  
     
  2. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    Do you have a pullup on pin 4 (MCLR)?
     
  3. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    Or just set _MCLR_OFF in the config bits. Check again if the clock speed you are using realy is 4MHz. Select a low data rate ke 9600 bit per second(if that can be done with 4MHz clock speed). I have also seen in datasheets from microchip that they warn about the internal osc used with UART my create errors. Not experienced this my self then using low data rates
     
  4. MaxHeadRoom

    Expert

    Jul 18, 2013
    10,571
    2,381
    If the USART is not running at the correct baud rate, you will just get garbled characters.
    The manual will show the % error for a certain clock/Baud rate.
    I have had no problem with 4mHz.
    Max.
     
  5. NomadAU

    Thread Starter Member

    Jul 21, 2012
    32
    0
    The MCLR was the problem....I just hooked up a 10k resistor from pin 4 to Vdd and all is working. Such a basic error, but another learning for me.
    BTW, before I made this change, the behaviour of the chip was affected just by the presence of my fingers. Without touching the chip, but putting my fingers close to it, I could make the LED come on. I guess this is due to me providing some capacitance and affecting the circuit, but I thought I'd mention this in case it helps anyone else with their diagnosis.
     
  6. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    Glad you got it sorted! :)

    As t06afre suggested, you can turn MCLR off in the configuration bits.

    The random behavior of your controller is due to leaving the reset floating, which will float to whatever is nearby...
     
    Last edited: Feb 13, 2014
  7. MaxHeadRoom

    Expert

    Jul 18, 2013
    10,571
    2,381
    I recall seeing the very same effect in the early days.
    Just waving your hand over the chip would make it do strange things.
    Max.
     
Loading...