test.asm


1
.nolist
2
.INCLUDE "tn26def.inc"
3
.list
4
5
6
;**********************************Registerbenennen**********************************************************
7
.def work=R16              ;hilfsregister
8
.def daten1L=R17
9
.def daten1H=R18
10
.def daten2H=R20
11
.def daten2L=R21
12
.def rmp=R19
13
.def temp1=R22
14
.def temp2=R23
15
.def temp3=R24
16
17
;******************************************************************************************************
18
.equ DIN=PORTB1
19
.equ LOAD=PORTB5
20
.equ CLK=PORTB2
21
;*********************************RESET und Interruptvektoren*********************************************************
22
rjmp RESET
23
reti
24
;**********************************Initialisierung*******************************************************
25
26
RESET:                      ;das Hauptprogramm fängt hier an**********************************************
27
28
ldi work,RAMEND            ;Höchste Adresse des SRAM speicher wird an dem Stack pointer zugewiesen
29
out SP,work
30
ldi work,(1<<PCIE0)        ;interrupt einstellen
31
out GIMSK,work
32
33
;port_A definieren
34
;alle pins unused
35
ldi work,(1<<DDA7)+(1<<DDA6)+(1<<DDA5)+(1<<DDA4)+(1<<DDA3)+(1<<DDA2)+(1<<DDA1)+(1<<DDA0)
36
out DDRA,work
37
38
;Port_B definieren
39
40
; pin7= RESET, pin6= UARTsenden, pin5=LOAD OUT , pin4-3= unused, pin2=SERIAL CLOCK,
41
; pin1= SERIAL DATA OUT pin0=UARTempfangen
42
ldi work,(0<<DDB7)+(1<<DDB6)+(1<<DDB5)+(1<<DDB4)+(1<<DDB3)+(1<<DDB2)+(1<<DDB1)+(0<<DDB0)
43
out DDRB,work
44
sei                        ;globale Interrupt Enable
45
;*****************************************************************************************************
46
;ENDLESS:
47
        nop
48
    nop
49
    nop
50
;rjmp ENDLESS
51
;*************************************************************************************************************
52
Probe:   ldi daten1H,0b00100111    ; 9999 laden
53
     ldi daten1L,0b00001111    ;
54
     rcall Ausgabe_init
55
     rcall BintoBcd
56
     ldi temp2,0x04
57
     ld temp1,z
58
     rcall Ausgabe
59
     st -z,temp1
60
     ldi temp2,0x03
61
     ld temp1,z
62
     rcall Ausgabe
63
     st -z,temp1
64
     ldi temp2,0x02
65
     ld temp1,z
66
     rcall Ausgabe
67
     st -z,temp1
68
     ldi temp2,0x01
69
     ld temp1,z
70
     rcall Ausgabe
71
         rjmp Probe
72
;*********************************************BCD convert************************************************
73
BintoBcd:
74
    ldi rmp,HIGH(1000)
75
    mov daten2H,rmp
76
    ldi rmp,LOW(1000)
77
    mov daten2L,rmp
78
    rcall BintoDigit
79
    ldi rmp,HIGH(100)
80
    mov daten2H,rmp
81
    ldi rmp,LOW(100)
82
    mov daten2L,rmp
83
    rcall BintoDigit
84
    ldi rmp,HIGH(10)
85
    mov daten2H,rmp
86
    ldi rmp,LOW(10)
87
    mov daten2L,rmp
88
    rcall BintoDigit
89
    st z,daten1L
90
    sbiw ZL,3
91
    ret
92
BintoDigit:
93
          clr rmp
94
BintoDigita:
95
            cp daten1H,daten2H
96
        brcs BintoDigitc
97
        brne BintoDigitb
98
        cp daten1L,daten2L
99
        brcs BintoDigitc
100
BintoDigitb:
101
            sub daten1L,daten2L
102
        sbc daten1H,daten2H
103
        inc rmp
104
        rjmp BintoDigita
105
BintoDigitc:
106
            st z+,rmp
107
            ret
108
109
110
;*********************************************MAX7219 initialisieren*************************************
111
Ausgabe_init:
112
             ldi temp2,0x09         ;decode address
113
       ldi temp1,0xFF         ;decode digit 7-0
114
       rcall Ausgabe
115
       ldi temp2,0x0A         ;helligkeit address
116
       ldi temp1,0x0F         ;max hell
117
       rcall Ausgabe
118
       ldi temp2,0x0B         ;scan adress
119
       ldi temp1,0x07         ;scan 8 digit
120
       rcall Ausgabe
121
       ldi temp2,0x0C         ;shutdown mode (stromsparfunktion)
122
       ldi temp1,0x01         ;normal operate(kein shutdown)
123
       rcall Ausgabe
124
       ldi temp2,0x0F         ;selbstest
125
       ldi temp1,0x01
126
       rcall Ausgabe
127
       ret
128
;***********************************MAX7219 AUSGABE***************************************************
129
Ausgabe:          CBI      PORTB,LOAD
130
                  LDI      temp3,16
131
SDP1:             CBI      PORTB,DIN
132
                  LSL      temp1
133
                  ROL      temp3
134
                  BRCC     SDP2
135
                  SBI      PORTB,DIN
136
SDP2:             CBI      PORTB,CLK
137
                  SBI      PORTB,CLK
138
                  DEC      temp1
139
                  BRNE     SDP1
140
                  SBI      PORTB,LOAD
141
                  RET