Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PICC 12F683 Digital Input GP Port Pull-up?

Status
Not open for further replies.

MikeMl

Well-Known Member
Most Helpful Member
I'm trying to use the Weak Pull Ups (WPU register) to pull-up GP5 and GP3, and I cannot get it to work. Both GP5 and GP3 seem to be floating inputs, in spite of my best efforts. I'm not sure if I'm doing something stupid, or if PICC is getting in my way?

Code:
/*

Simple timer using 12F683

Desired behavior at Port Pins:
---------------------------------------------------------------------------
GP0 always driven as an output (YES)
GP1,GP2 is an output which is either hiZ or driven Low (YES)
GP3 is not used as MCLR, therefore is input, pulled high by WPU bit (NO)
GP4 is CLKOUT (YES)
GP5 is input, pulled high by WPU (NO)
*/

#include <12F683.h>
#use delay(clock=125000)
#use fast_io(A)
#byte WPU=0x95                            //my attempt at enabling pull ups
#fuses NOWDT,INTRC, NOCPD, NOPROTECT, NOMCLR, PUT, BROWNOUT, IESO, FCMEN

void main()
{
   unsigned long cnt;                     //16 bit counter
   setup_adc_ports(NO_ANALOGS|VSS_VDD);
   setup_adc(ADC_OFF);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_32);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   setup_oscillator( OSC_125KHZ | OSC_INTRC);  //switch to slow internal clock

   output_A(0);                           //set all port bits low.                      
   WPU=0x28;                              //pull up GP5 and GP3
   
   do
   {  set_tris_A(0b00101110);             //float GP1 & GP2
      
      for(cnt=0;cnt<=20;++cnt)            //cnt<=65535 is 23 hours
      {  output_A(1);                     //tick bit high
         delay_ms(1163);                  //delay 1.163 sec
         output_A(0);                     //tick bit low
         delay_ms(100);                   //delay 0.1 sec
      }
      
      set_tris_A(0b00101000);             //Drive GP1 & GP2 LOW

      for(cnt=0;cnt<=10;++cnt)            //cnt<=2848 is one hour
      {  output_A(1);                     //tick bit high
         delay_ms(631);                   //delay 0.631 sec 
         output_A(0);                     //tick bit low
         delay_ms(632);                   //delay 0.632 sec 
      }
   }      
   while (1);                             //loop forever
}
 
Last edited:
Answered my own question. I had to read the data sheet about three times, and pick through the output of the compiler. Generates the following code. Note that for whatever reason, when using the PORT_A_PULLUPS(true) function, it only sets the LSB of the WPU register, so by putting the WPU= statement AFTER the PORT_A_PULLUPS(true) call, I got it to work, sort of. It works for GP5, but for GP3, the weak pullup resistor is used only when the pin is as MCLR, so when used as a digital input, I will have to wire in my own weak pullup.

Look at the code produced by the compiler...
Code:
....................    port_A_Pullups(True);                  //Clear bit 7 in OPTION_REG
003F:  MOVLW  01
0040:  BSF    03.5
0041:  MOVWF  15
0042:  BCF    01.7
....................    WPU=0x28;                              //pull up GP5 and GP3 (this order)
0043:  MOVLW  28
0044:  MOVWF  15
....................
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top