Advertisement
Guest User

Untitled

a guest
Dec 10th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.58 KB | None | 0 0
  1. #define ADR_8255_PORTA 0x08
  2. #define ADR_8255_PORTB 0x00
  3. #define ADR_8255_PORTC 0x0A
  4. #define ADR_8255_CW 0x02
  5.  
  6. #define ADR_8254_CNT0 0x180
  7. #define ADR_8254_CNT1 0x190
  8. #define ADR_8254_CNT2 0x184
  9. #define ADR_8254_CW 0x194
  10.  
  11. #define ADR_8259_0 0x4100
  12. #define ADR_8259_1 0x4120
  13.  
  14.  
  15. typedef unsigned short Word16;
  16. typedef unsigned char Byte8;
  17.  
  18. Byte8 min = 0, sec = 0;
  19. Byte8 tekCif = 0;
  20. Byte8 cifre[4];
  21.  
  22. Byte8 segmenti[] = {0x06, 0x5b, 0x4f, 0x66};
  23.  
  24. void outp(Word16 addr, Byte8 data){
  25. _asm {
  26. push dx
  27. push ax
  28. mov dx, addr
  29. mov al, data
  30. out dx, al
  31. pop ax
  32. pop dx
  33. }
  34. }
  35.  
  36. Byte8 dohvatiCifru(Byte8 cif) {
  37. if(cif < 4) {
  38. return cifre[cif];
  39. }
  40. return 10;
  41. }
  42.  
  43. Byte8 dekodujCifru(Byte8 cif) {
  44. if(cif < 4) {
  45. return segmenti[cif];
  46. }
  47. return 10;
  48. }
  49.  
  50. void pritisniDugme() {
  51. int i;
  52. min = sec = 0;
  53. for (i = 0; i<4; i++) {
  54. cifre[i] = 0;
  55. }
  56. }
  57. void timer0(){
  58.  
  59. Byte8 cifzaprikaz, sadrzajzaprikaz;
  60. outp(ADR_8255_PORTA, 0xFF);
  61. tekCif = (tekCif + 1) % 4;
  62. cifzaprikaz = dohvatiCifru(tekCif);
  63. sadrzajzaprikaz = dekodujCifru(cifzaprikaz);
  64. outp(ADR_8255_PORTB, sadrzajzaprikaz);
  65. switch(tekCif) {
  66. case 0 :
  67. outp(ADR_8255_PORTA, 0xF7);
  68. break;
  69.  
  70. case 1 :
  71.  
  72. outp(ADR_8255_PORTA, 0xFE);
  73. break;
  74.  
  75. case 2 :
  76.  
  77. outp(ADR_8255_PORTA, 0xFB);
  78. break;
  79.  
  80. case 3 :
  81.  
  82. outp(ADR_8255_PORTA, 0xFD);
  83. break;
  84.  
  85. default : break;
  86. }
  87.  
  88. }
  89.  
  90. Byte8 inp(Word16 addr) {
  91. Byte8 res;
  92. _asm {
  93. push dx
  94. mov dx, addr
  95. in al, dx
  96. mov res, al
  97. pop ax
  98. }
  99. return res;
  100. }
  101.  
  102. void init8255() {
  103. outp(ADR_8255_CW, 0x80);
  104.  
  105. outp(ADR_8255_PORTA, 0xFF);
  106. }
  107.  
  108. void init8254() {
  109. //outp(ADR_8254_CW, 0xb6); //cnt2
  110. outp(ADR_8254_CW, 0x16); //cnt0
  111.  
  112. //outp(ADR_8254_CNT2, 0xe8);
  113. //outp(ADR_8254_CNT2, 0x03);
  114.  
  115. outp(ADR_8254_CNT0, 0x0F);
  116.  
  117. }
  118.  
  119. void init8259() {
  120. outp(ADR_8259_0, 0x13);
  121. outp(ADR_8259_1, 0x20);
  122. outp(ADR_8259_1, 0x01);
  123.  
  124. outp(ADR_8259_0, 0x0B); //ISR tj OCW3
  125. }
  126.  
  127. void timer2() {
  128.  
  129. }
  130.  
  131.  
  132. void interrupt prekidnaRutina() {
  133. Byte8 procitaniISR, maska = 0x01, i;
  134. procitaniISR = inp(ADR_8259_0);
  135.  
  136. for (i = 0; i < 6; i++) {
  137. if(procitaniISR & maska) break;
  138. maska <<= 1;
  139. }
  140. switch(i) {
  141. case 0 :
  142. pritisniDugme();
  143. outp(ADR_8259_0, 0x60 | i);
  144. break;
  145.  
  146. case 2 :
  147. timer2();
  148. outp(ADR_8259_0, 0x60 | i);
  149. break;
  150.  
  151. case 5 :
  152. timer0();
  153. outp(ADR_8259_0, 0x60 | i);
  154. break;
  155.  
  156. default : break;
  157. }
  158.  
  159.  
  160. }
  161.  
  162. void glavniProgram() {
  163. init8255();
  164. init8259();
  165. init8254();
  166.  
  167.  
  168. _asm sti;
  169. outp(ADR_8259_1, 0xDA);
  170.  
  171.  
  172. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement