Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define ADR_8255_PORTA 0x08
- #define ADR_8255_PORTB 0x00
- #define ADR_8255_PORTC 0x0A
- #define ADR_8255_CW 0x02
- #define ADR_8254_CNT0 0x180
- #define ADR_8254_CNT1 0x190
- #define ADR_8254_CNT2 0x184
- #define ADR_8254_CW 0x194
- #define ADR_8259_0 0x4100
- #define ADR_8259_1 0x4120
- typedef unsigned short Word16;
- typedef unsigned char Byte8;
- Byte8 min = 0, sec = 0;
- Byte8 tekCif = 0;
- Byte8 cifre[4];
- Byte8 segmenti[] = {0x06, 0x5b, 0x4f, 0x66};
- void outp(Word16 addr, Byte8 data){
- _asm {
- push dx
- push ax
- mov dx, addr
- mov al, data
- out dx, al
- pop ax
- pop dx
- }
- }
- Byte8 dohvatiCifru(Byte8 cif) {
- if(cif < 4) {
- return cifre[cif];
- }
- return 10;
- }
- Byte8 dekodujCifru(Byte8 cif) {
- if(cif < 4) {
- return segmenti[cif];
- }
- return 10;
- }
- void pritisniDugme() {
- int i;
- min = sec = 0;
- for (i = 0; i<4; i++) {
- cifre[i] = 0;
- }
- }
- void timer0(){
- Byte8 cifzaprikaz, sadrzajzaprikaz;
- outp(ADR_8255_PORTA, 0xFF);
- tekCif = (tekCif + 1) % 4;
- cifzaprikaz = dohvatiCifru(tekCif);
- sadrzajzaprikaz = dekodujCifru(cifzaprikaz);
- outp(ADR_8255_PORTB, sadrzajzaprikaz);
- switch(tekCif) {
- case 0 :
- outp(ADR_8255_PORTA, 0xF7);
- break;
- case 1 :
- outp(ADR_8255_PORTA, 0xFE);
- break;
- case 2 :
- outp(ADR_8255_PORTA, 0xFB);
- break;
- case 3 :
- outp(ADR_8255_PORTA, 0xFD);
- break;
- default : break;
- }
- }
- Byte8 inp(Word16 addr) {
- Byte8 res;
- _asm {
- push dx
- mov dx, addr
- in al, dx
- mov res, al
- pop ax
- }
- return res;
- }
- void init8255() {
- outp(ADR_8255_CW, 0x80);
- outp(ADR_8255_PORTA, 0xFF);
- }
- void init8254() {
- //outp(ADR_8254_CW, 0xb6); //cnt2
- outp(ADR_8254_CW, 0x16); //cnt0
- //outp(ADR_8254_CNT2, 0xe8);
- //outp(ADR_8254_CNT2, 0x03);
- outp(ADR_8254_CNT0, 0x0F);
- }
- void init8259() {
- outp(ADR_8259_0, 0x13);
- outp(ADR_8259_1, 0x20);
- outp(ADR_8259_1, 0x01);
- outp(ADR_8259_0, 0x0B); //ISR tj OCW3
- }
- void timer2() {
- }
- void interrupt prekidnaRutina() {
- Byte8 procitaniISR, maska = 0x01, i;
- procitaniISR = inp(ADR_8259_0);
- for (i = 0; i < 6; i++) {
- if(procitaniISR & maska) break;
- maska <<= 1;
- }
- switch(i) {
- case 0 :
- pritisniDugme();
- outp(ADR_8259_0, 0x60 | i);
- break;
- case 2 :
- timer2();
- outp(ADR_8259_0, 0x60 | i);
- break;
- case 5 :
- timer0();
- outp(ADR_8259_0, 0x60 | i);
- break;
- default : break;
- }
- }
- void glavniProgram() {
- init8255();
- init8259();
- init8254();
- _asm sti;
- outp(ADR_8259_1, 0xDA);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement