Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <avr/io.h>
- #include <util/delay.h>
- void ispis_7SEG (unsigned char karakter, unsigned char pozicija){
- PORTB = ~(0x01 << (4-pozicija)); //ukljucenje displeja na zeljenoj
- //poziciji
- PORTD = karakter; //prikaz karaktera
- _delay_ms(5); //pauza 2ms
- }
- //makroi za kontrolu pinova preko kojih je kontroler povezan sa 74HC165:
- #define SCL_HI (PORTC |= (1<<5))
- #define SCL_LO (PORTC &= ~(1<<5))
- #define SDA (PINC & (1 << 4))
- #define SHLD_HI (PORTB |= (1<<5))
- #define SHLD_LO (PORTB &= ~(1<<5))
- unsigned char ocitaj_prekidace()
- {
- unsigned char i, tmp = 0, mask = 0x80;
- SHLD_HI;
- SHLD_LO;
- SHLD_HI; //impuls za upis stanja prekidaca u registar
- for (i=0; i<8; i++)
- {
- SCL_LO;
- SCL_HI; //generisanje aktivne ivice takta
- if (SDA) //provera stanja ulaznog pina
- tmp |= mask;
- mask >>= 1;
- }
- return tmp;
- }
- #define DISP_P ~0b11110001
- #define DISP_R ~0b11010000
- #define DISP_A ~0b11110011
- #define DISP_G ~0b11101011
- #define DISP_O ~0b11111010
- #define DISP_S ~0b11001011
- #define DISP_L ~0b01011000
- #define DISP_M ~0b11100000
- #define DISP_I ~0b01010000
- int main()
- {
- int i;
- int pauza= 128;
- DDRD = 0xFF; //PB5 je izlaz
- DDRB = 0x2F;
- DDRC = 0x20;
- while (1)
- {
- //ispis_7SEG((ocitaj_prekidace()>>4) & 0b00000011,1);
- switch((ocitaj_prekidace()>>4) & 0b00000011){
- case 0:pauza = 0;
- break;
- case 1:pauza = 128;
- break;
- case 2:pauza = 256;
- break;
- case 3:pauza = 512;
- break;
- default:pauza = 0;
- }
- for(i = 0; i < pauza;i++){
- switch(ocitaj_prekidace()>>6){
- case 0:
- ispis_7SEG(DISP_P,1);
- ispis_7SEG(DISP_R,2);
- ispis_7SEG(DISP_A, 3);
- ispis_7SEG(DISP_G, 4);
- break;
- case 1:
- ispis_7SEG(DISP_O,1);
- ispis_7SEG(DISP_S,2);
- ispis_7SEG(DISP_L, 3);
- ispis_7SEG(DISP_O, 4);
- break;
- case 2:
- ispis_7SEG(DISP_R,1);
- ispis_7SEG(DISP_I,2);
- ispis_7SEG(DISP_M, 3);
- ispis_7SEG(0xFF, 4);
- break;
- case 3:
- ispis_7SEG(DISP_R,1);
- ispis_7SEG(DISP_I,2);
- ispis_7SEG(DISP_G, 3);
- ispis_7SEG(DISP_A, 4);
- break;
- default:
- PORTD = 0xff;
- }
- }
- PORTD = 0xff;
- for(i = 0; i < pauza;i++)_delay_ms(8);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement