Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

4 digit 7- segment with 16f676

Status
Not open for further replies.

sahu

Advanced Member level 2
Advanced Member level 2
Joined
Oct 9, 2009
Messages
519
Helped
68
Reputation
130
Reaction score
63
Trophy points
1,308
Location
Uttar pradesh (INDIA)
Visit site
Activity points
3,927
i have need read more then 1 adc with 16f676,but no left adc pin on this code .if i use 7447 BCD to 7 Segment driver IC .then it possible with this code .
PHP:
#include <htc.h>
__CONFIG (FOSC_INTRCIO & MCLRE_OFF & BOREN_ON & CP_OFF & CPD_OFF & WDTE_OFF & PWRTE_ON ); 



#define SPORT PORTA
#define DPORT PORTC
const char SegCode[11] ={0xC0, 0xF9, 0xA4, 0xB0, 0x99, 0x92, 0x82, 0xF8,  0x80, 0x90, 0xFF};//  {0x40,0x57,0x22,0x06,0x15,0x0C,0x08,0x56,0x00,0x04,0xFF};
    //                       0    1    2    3    4    5    6    7    8    9
const char Column[3]   = {0x02,0x01,0x04};
static char Segment[3] = {0x7f,0x7f,0x7f};    
static unsigned char ColCount=0x00;
void CPU_SETUP(void);
void Display(void);
void HTO7S(unsigned int Num);
void delayMs(int x);

unsigned int result;
unsigned int readAdc(void);
void interrupt  timer1_isr(void)
{
if(PIR1bits.TMR1IF==1)
{
PIR1bits.TMR1IF = 0;
    TMR1H=0xDF;
Display();
}
}
void main()
{        
    unsigned char i;
    
    CPU_SETUP();
    while(1)
    {            
        result=0;
        for (i=0;i<3;i++)
        {
            
            delayMs(1); 
            result=result+readAdc();
        }
                HTO7S(result/3);                                
        
        delayMs(200);            
    }
    
}

void CPU_SETUP()
{
    CMCON =0x07;        //Turn off comparator module
    ANSEL =0x8;            //AN3 as analog input
    ADCON1 =0x60;         //clock/64
    ADCON0 = 0x8D;
       TRISA=0b00011000;
       PORTA=0x27;
       TRISC=0b00000000;
       PORTC=0x37;
   
   T1CON= 0x00;
      TMR1H=0xDF;
       INTCONbits.GIE =1;
    INTCONbits.PEIE=1;
    PIE1bits.TMR1IE =1;
     T1CONbits.TMR1ON=1;
}
unsigned int readAdc()
{
unsigned int res;
ADCON0bits.GO_DONE =1;
while(ADCON0bits.GO_DONE ==1);
res=ADRESL+(ADRESH*0x100);
return(res);
}
//-------------------------------------
// Display routine
//-------------------------------------
void Display()
{
    PORTA = 0b00100111;      // off all digits column and Segment G
    PORTC = 0b00111111;   // off segment a-f    

    

    if (ColCount>=3) 
    ColCount=0;
        
    DPORT = Segment[ColCount];
    SPORT = ((Segment[ColCount] & 0b01000000)>>1) | (Column[ColCount]^0x07);
    ColCount++;                
}    

//--------------------------------------
// Convet HEX 2 byte to 7-Segment code
//--------------------------------------
void HTO7S(unsigned int Num)
{
    
    unsigned int res;

    res = ((30*Num)%1023)/100;
    if(res==10)
    {
    Num=Num+1;
    res=0;
    }
    Segment[2]=SegCode[res];

    res = (30*Num)/1023;
    Segment[1]=SegCode[res%10];

    Segment[0]=SegCode[res/10];
    if (Segment[0]==0x40) 
    Segment[0]=0xFF;    
    
}    

void delayMs(int x)
{
int i;
for (x ;x>0;x--)
{
for (i=0;i<=110;i++);
}
}
we can use 7447 BCD to 7 Segment driver IC with 16f676 as

PHP:
                     _______
                vdd | 1  14 | Vss
 DIGIT_1000 <-- RA5 | 2  13 | AN0 <-- ADC0
  DIGIT_100 <-- RA4 | 3  12 | AN1 <-- ADC1
               MCLR | 4  11 | AN2 <-- ADC2
   DIGIT_10 <-- RC5 | 5  10 | RC0 --> A
    DIGIT_0 <-- RC4 | 6   9 | RC1 --> B
          D <-- RC3 | 7   8 | RC2 --> C
                     _______
 

And?
You can use MAX7219 also. It needs only 3 pins.
Or i2c port expander. It needs only 2.
But the right way is to use another mcu with more pins.
 

And?
You can use MAX7219 also. It needs only 3 pins.
Or i2c port expander. It needs only 2.
But the right way is to use another mcu with
more pins.
here the essu of completed ckt cost of production
7447 cost in India INR 5 only .
I can use an other MCU , cost I most important for me.
 

You can use 74HC595 to drive the SSDs. If you have 3 SSDs then you can cascade 3 HC595's. They need only 3 pins of MCU.
 

74HC595 shift register?

yes i can use 595 in place of 7447 .
can u help me .

PHP:
                     _______
                vdd | 1  14 | Vss
 DIGIT_1000 <-- RA5 | 2  13 | AN0 <-- ADC0
  DIGIT_100 <-- RA4 | 3  12 | AN1 <-- ADC1
               MCLR | 4  11 | AN2 <-- ADC2
   DIGIT_10 <-- RC5 | 5  10 | RC0 --> DS
    DIGIT_0 <-- RC4 | 6   9 | RC1 --> ST_CP
            <-- RC3 | 7   8 | RC2 --> SH_CP
                     _______
 
Last edited:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top