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.

Two digit counter using pic16f72

Status
Not open for further replies.

koolguy

Active Member
Hi again,

I was testing a two seven segment display multiplexed with PIC16F72, the problem is that i am using two switch for Up and down the counter. The seven segment look table is made in array.
which is working fine with for loop.
But now i want to up the counter with pressing the switch and down.
for this this code is not working fine pull down Resistance is used for reference values.
C:
char data[12]={0xDE,0X50,0b10111010,0b11111000,0b01110100,0b11101100,0b11101110,0b01011000,0b11111110,0b11111100} ;
main()
   {
   TRISB = 0 ;
   TRISC = 0 ;
   ADCON0=0X00;
   ADCON1=0B11111111;
   TRISA = 0b11111100 ;
   __delay_ms(500);
   unsigned char a=0;
   while(1){

      PORTA=0b00000010;//digit one multiplex
      PORTB=data[a];// counter loaded value
      __delay_ms(10);


      PORTA=0b00000001;//digit one multiplex
      PORTB=data[0]; // just used for test working fine or not
      __delay_ms(10);

      if(RA2==1){
         __delay_ms(400);
         a=a+1;
      }
      if(RA3==1){
         __delay_ms(400);
         a=a-1;
      }
  }
}
 
Last edited by a moderator:
Surely after 1,600 posts you know how to use code tags? Please edit your post, add code tags and indentation.

Mike.
 
Whats happening??? Have you a pull down resistor on RA0 and RA1? and the switch connected to +v
The RA0 AND RA1 is used as digital output for multiplexed and RA2 AND RA3 is used for switch which is pulled down and switch is tied up with +5V.
so, the problem is in counting up and down which is creating problem. i need only one digit rest i will use % and / for making ten and unit digit.
 
You said:
so, the problem is in counting up and down which is creating problem. i need only one digit rest i will use % and / for making ten and unit digit.
What problem?? Elaborate.... Not counting? Not displaying?
 
No disrespect here!! But what does this relate to:..

char data[12] = {0xDE,0x50,0b10111010,0b11111000,0b01110100,0b11101100,0b11101110,0b01011000,0b11111110,0b11111100} ;

they don't seem to make any numbers whatsoever!
 
I have re-witten the digits to suit my application.. Your problem is with the ADCON1 register... Set the thing to 0x07 and all the adc's are off the way you have it set the Vref's are on....Rendering the RA2 and RA3 useless..

Otherwise it works tickey boo...
 
Hello again,
The problem was solved using mp lab Sim debugger yesterday..
anyway, the seven segment display i am using i have made look table working fine.
thanks
cpd-1012cur2/c
 
Hello hello,
The code get success working cool...!!

C:
 #include <htc.h>
#include <stdio.h>

__CONFIG( BOREN_OFF & PWRTE_ON & WDTE_OFF & FOSC_HS & CP_OFF );

#define _XTAL_FREQ 20000000
char data[12]={0xDE,0X50,0xBA,0XF8,0X74,0XEC,0XEE,0X58,0XFE,0XFC} ;
main()
    {
    TRISB = 0 ;
    TRISC = 0 ;
ADCON0=0X00;
ADCON1=0B11111111;
TRISA = 0b11111100 ;
__delay_ms(500);
unsigned char a=0;
unsigned char div=0;
unsigned char rem=0;
    while(1){
rem = a%10;
PORTA=0b00000010;
PORTB=data[rem];
__delay_ms(10);

div=a/10;
PORTA=0b00000001;
PORTB=data[div];
__delay_ms(10);

if(RA2==1){
__delay_ms(80);
a=a+1;
if(a>99){
a=99;
}

}


  if(RA3==1){
__delay_ms(80);
a=a-1;
if(a>99){
a=0;
}
}
    
                } 
                }
 
Ritesh,

Can I suggest you take the time to indent your code as this will let you see more clearly the code flow. Look at the code in the first post (which I assume was formatted by Ian) and see how much easier it is to follow when properly indented.

BTW, congratulations on getting it working.

Mike.
 
Now, i am connecting a capacitor to save in internal volatile memory of it!
for this i need to calculate the time period the data will be saved by connecting C=22,000uF only with microcontroller not led display.
how to do this??
 
Good!!
I looked at your segments.... Instead of wiring them a, b, c, d, e, f, g, dp yours are dp, e, f, d, b, g, c, a

Glad it works.... I'm not sure why your ADC isn't messing it up though... It should be ADCON1 = 0x7
 
I don't understand why at start up it show 23 , but not exact 2.
if up is press it shows 99 and at down shows 00, but according to code a=0; so it should be 00...
 
OK, For this we have to use Series Resistance with PIC micro controller, is that will be fine ??
how much value??
 
If your circuit takes 5mA then a 2200uF cap will last about 500mS before the voltage is 3.9v
Only micro controller not display anyway what is the procedure for calculating?
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top