Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .include "m16def.inc"
- .list
- .def temp = r16
- .def sys = r17
- .def trns = r18
- .def str = r19
- .def k = r20
- .def msumb1 = r21
- .def msumb2 = r22
- .equ bitrate =38400
- .equ BAUD=8000000/(16*bitrate)-1
- .cseg
- .org 0
- rjmp RESET
- //.org $009
- //rjmp USART_RXC
- //.org $00B
- //rjmp USART_TXC
- ;;Interrupt table definition
- .org INT0addr
- rjmp INT0_IRQ
- .org INT1addr
- rjmp INT1_IRQ
- .org OC1Aaddr
- rjmp OC1A_IRQ
- .org OC1Baddr
- rjmp OC1B_IRQ
- .org OVF1addr
- rjmp OVF1_IRQ
- INT0_IRQ:
- reti
- ;INT1_IRQ:
- ;reti
- OC2_IRQ:
- reti
- OVF2_IRQ:
- reti
- ICP1_IRQ:
- reti
- ;OC1A_IRQ:
- ;reti
- OC1B_IRQ:
- reti
- OVF1_IRQ:
- reti
- RESET:
- clr msumb1
- clr msumb2
- ;Stack Init
- ldi temp,low(RAMEND)
- out SPL,temp
- ldi temp,high(RAMEND)
- out SPH,temp
- ;USART Init
- ;BAUD=19600 bit/sec
- ldi sys,high(BAUD)
- out UBRRH,sys
- ldi sys,low(BAUD)
- out UBRRL,sys
- ;
- ldi sys,(1<<TXEN)|(1<<RXEN) ; TXEN=1)
- out UCSRB,sys
- ;UCSZ0 UCSZ1 =1 => 8 bit + URSEL=1 (1 stop-bit)
- ldi sys,(1<< URSEL)|(1<< UCSZ0)|(1<< UCSZ1)
- out UCSRC,sys
- ;Low Level Signal
- ldi temp,(0<<PORTD3)
- out PORTD,temp
- ;INT1 External Interrupt Init
- ldi sys, (1<<ISC11)|(1<<ISC10)
- out MCUCR,sys
- clr sys
- ldi sys,(1<<INTF1)
- out GIFR,sys
- ldi sys,(1<<INT1)
- out GICR,sys
- ;Button Init
- ldi sys,(0<<PIND7)
- out PIND,sys
- clr temp
- clr sys
- out DDRB,temp
- out DDRA, temp
- ldi temp,(1<<PORTD3)
- out PORTD,temp
- clr sys
- //TIMER1 (16 bit) Initialization; Output Compare A Match Interrupt Enable
- ldi temp,(1<<OCIE1A)
- out TIMSK,temp
- //Set Output Compare Register A; 1562 <=> 5 Hz
- ldi temp,high(500)
- out OCR1AH,temp
- ldi temp,low(500)
- out OCR1AL,temp
- clr temp
- //Timer/Counter Init
- out TCNT1H,temp
- out TCNT1L,temp
- //CS12-CS10 Clock Select in 1024 prescaller
- ldi temp,0b00001101
- out TCCR1B,temp
- clr temp
- sei
- loop:
- rjmp loop
- INT1_IRQ:
- cli
- sbic PIND,PIND7;skip if 0
- rjmp leave
- ;sbis PIND,PIND6;skip if 1
- ;rcall scorebutton
- SEND0:
- sbis UCSRA,UDRE
- rjmp SEND0
- in sys,PINA //
- ;mov msymb1,sys //msymb1=byte1
- out UDR,sys //
- //
- rcall check //
- //
- SEND1:
- sbis UCSRA,UDRE
- rjmp SEND1
- in trns,PINB
- out UDR,trns
- //
- rcall check
- //counting msum
- adc sys,trns //trns=byte2, sys=byte1
- in msumb1, SREG
- sbrc msumb1,0 //skip if 0//if C in SREG = 1 => msumb2=00000001
- ldi msumb2,0b00000001
- mov msumb1,sys // msumb1= the first 8 bit of msum
- chksum2:
- sbis UCSRA,UDRE
- rjmp chksum2
- out UDR,msumb2
- //
- rcall check
- //
- chksum1:
- sbis UCSRA,UDRE
- rjmp chksum1
- out UDR,msumb1
- //
- rcall check
- //
- SEND2:
- sbis UCSRA,UDRE
- rjmp SEND2
- ldi str,0x0A
- out UDR,str
- //
- rcall check
- //
- SEND3:
- sbis UCSRA,UDRE
- rjmp SEND3
- ldi str,0x0D
- out UDR,str
- //
- rcall check
- //
- leave:
- clr sys
- reti
- check:
- sei
- push r14
- ldi temp,0b00001101
- out TCCR1B,temp
- receive:
- sbis UCSRA,RXC
- rjmp receive
- clr temp
- out TCCR1B,temp
- sbic 20, 0
- rjmp loop
- clr temp //
- out TCCR1B,temp
- in temp,UDR
- clr temp
- pop r14
- ret
- OC1A_IRQ:
- clr temp
- out TCCR1B,temp
- ldi r20,0b00000001
- EE:
- sbis UCSRA,UDRE
- rjmp EE
- ldi temp,0xEE
- out UDR,temp
- reti
- rjmp RESET
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement