7SEGMENT


//singlePORT
#include <mega16.h>
#include <delay.h>

// Declare your global variables here
unsigned char bil[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90}; //common anoda
//unsigned char bil[10]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F}; // common katoda
void main(void)
{
// Declare your local variables here
int sevsegKiri, sevsegKanan, i;
DDRC = 0XFF;
DDRD = 0XFF;
PORTC = 0X00;
PORTD = 0XFF;

while (1)
      {
      // Place your code here
      sevsegKiri=0;
      sevsegKanan=0;

      for(sevsegKiri=0;sevsegKiri<10;sevsegKiri++)
        {
            for(sevsegKanan=0;sevsegKanan<10;sevsegKanan++)
            {
            for(i=0;i<1;i++)
            {
                PORTC.0=0;
                PORTC.1=1;
                PORTD=bil[sevsegKanan];
                delay_ms(5);

                PORTC.0=1;
                PORTC.1=0;
                PORTD=bil[sevsegKiri];
                delay_ms(5);
}
}     }
}
}


//buat 7seg double PORT
#include <io.h>
#include <delay.h>
// Declare your global variables here
unsigned char bil[10]=
{0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
void main(void)
{
// Declare your local variables here
int kiri, kanan, i;

DDRD=0XFF;
DDRC=0XFF;
PORTD=0XFF;
PORTC=0XFF;

while (1)
    {
    kiri=0;
    kanan=0;
    for (kiri=0;kiri<10;kiri++)  //puluhan
    { for (kanan=0;kanan<10;kanan++)  //satuan
    { for (i=0;i<10;i++)
    {
    PORTD=bil[kanan];
    delay_ms(1);
    PORTC=bil[kiri];
    delay_ms(1);
    }
    }
    }}
}

Komentar

Postingan Populer