XC8 Code for PIC10F320 – PIC10F322 –  WPUA – XC8 Code – Weak Pull Ups

Some days you want to pull your hair out.  Datasheet read one thing – what happens in the real world is different.

Supposedly, unless I am reading it wrong the PIC10F322 has internal Weak Pull Up Resistors on all the GPIO ports. Each one should be individually selected.

For those who might not know what an internal weak pull up is – it will tie a pin to positive voltage.  Just like adding an external 10K resistor to positive rail.  Grounding the line – will pull it to a 0 state.   Except it removes the external resistor part.

I even wrote a nice interface for it.  enableWPUA(); and disableWPUA(); found in my GitHub area in the wpua.c and wpua.h files.

However – I thought this would be a quick little post I would write up – one of those things you think.. It will just take 5 minutes..  Not..

After my first attempt of getting the weak pull ups enabled on PORTA.1, then PORTA.0..  Ended with failure.

Short story and a lot more than 5 minutes. It appears that the pull ups only work on PORTA.2 and PORTA.3.  Maybe I have a bad CPU – replaced it with a new one.. Same results.  Maybe a bad batch???

Anyway – below is the code for the weak pull up working on PORTA.2.  To get the LED to light on PORTA.0 – a button is connected to PORTA.2 which is being held HIGH by the internal pull up.  Grounding the pin will bring the PIN to a logic 0 level – causing the LED to light.  When the button is released – the PIN goes back to logic level 1 and the LED goes off.


The code and include files can be found here in GitHub – https://github.com/JamieStarling/MCU_FUN/tree/master/Microchip/PIC10F322  led_button_control.c


Something to note about the logic in the code – since we are using weak-pullups – this will bring a PIN to logic level 1 {HIGH} (+5) – this will be the default state.  What the logic does is;  if PORTA.2 is HIGH, turn the LED off – because the button is not pressed.  When the button is pressed PORTA.2 will be LOW – when it is LOW – turn on the LED.


 * File:   main.c
 * Author: Jamie
 * Created on August 2, 2020, 12:52 PM

#include "includes/10F322_deviceconfig.h"
#include "includes/gpio.h"
#include "includes/wpua.h"

void main(void)