;***************************************************************************** ;TITLE : Program to interrupt the microcontroller in multiples of 10msec. ; ;Format of instruction: On resetting the controller 'A' is displayed. Enter ; a four digit multiplier for the interval. Interrupt ; is generated after the required interval which ; toggles PINB6. Interrupt count is entered in HEX ; format. Also the HEX value entered is the multiple ; of 10msec. Example: if value entered is 0002, then ; the PINB6 will be toggled after every 20msec. ; ;Crystal frequency : 3.58 MHz. ;Baud rate : 2400 ; ;***************************************************************************** .include "2313def.inc" .def mncnt0 = r2 .def mncnt1 = r3 .def rtemp = r16 .def auxcnt0 = r17 .def auxcnt1 = r18 .def rreg = r19 .def treg = r20 .def cnt = r21 .def datbyt = r22 .def rtemp1 = r23 .cseg .org 0 rjmp reset .org 4 rjmp t1intr RESET: ldi rtemp,$A0 ; initialise stack pointer out SPL,rtemp ldi rtemp,$5A ; setting baud rate to 2400 at crystal out UBRR,rtemp ; frequency of 3.58 MHz bck: ldi treg,$41 ; display 'A' on comp screen rcall txcomp ldi rtemp,$80 ; enable all interrupts out SREG,rtemp ldi rtemp,$40 ; enable timer1 output compare match interrupt out TIMSK,rtemp ldi rtemp,$00 ; disconnect pin OC1 from timer & PWM out TCCR1A,rtemp ; operation is disabled ldi rtemp,$08 ; timer 1 stopped out TCCR1B,rtemp ldi rtemp,0b11111111 ; initialize PORTB as output port out DDRB,rtemp ldi rtemp,$11 ; load count in compare register out OCR1AH,rtemp ldi rtemp,$7B out OCR1AL,rtemp ldi rtemp,$00 ; load 0000 in timer 1 register out TCNT1H,rtemp ldi rtemp,$00 out TCNT1L,rtemp ldi auxcnt0,$00 ; initialisation of auxiliary count ldi auxcnt1,$00 ; rcall receive ; get interval value from user. store mov mncnt1,datbyt ; higher value in mncnt1 & lower value rcall receive ; in mncnt0 mov mncnt0,datbyt ldi rtemp,$00 cpse mncnt0,rtemp ; if lower value = 0 , rjmp nxt cpse mncnt1,rtemp ; then if higher value = 0 rjmp nxt1 rjmp bck ; then go back nxt1: dec mncnt1 ; else dec higher value nxt: dec mncnt0 ; decrement lower value ldi rtemp,0b00001010 ; start timer 1 & prescale clk/8 out TCCR1B,rtemp here: nop rjmp here ;***************************************************************************** ;'t1intr' ;Aim ; Interrupt service routine for timer 1 compare match. ;Registers used ; auxcnt1,auxcnt0 store auxiliary count value msb(1), lsb(0) ; mncnt1,mncnt0 store main count value msb(1), lsb(0) ; datbyt to pass value to displaying function ;Functions called ; transmit ;***************************************************************************** t1intr: cpse auxcnt1,mncnt1 ; if higher bytes are not equal rjmp t1nxt ; then jmp to t1nxt cpse auxcnt0,mncnt0 ; else if lower bytes are not equal rjmp t1nxt ; then jmp to t1nxt in rtemp,PORTB ; read PORTB ldi rtemp1,0b01000000 eor rtemp,rtemp1 ; complement PORTB6 out PORTB,rtemp ; out PORTB ldi auxcnt0,$00 ldi auxcnt1,$00 rjmp t1nxt1 t1nxt: inc auxcnt0 ; increment lower byte of aux counter cpi auxcnt0,$00 ; if it is zero then increment higher brne t1nxt1 ; byte of aux counter, else go to inc auxcnt1 ; calling function t1nxt1: reti ;***************************************************************************** ;'receive' ;Aim ; Function to receive 8 bits (2 digits) from comp ;Registers used ; rreg : contains hex data from user ; datbyt : contains packed data byte which is ; transferred to calling function ;Functions called ; rxcomp ; asctohex ;***************************************************************************** receive: rcall rxcomp ; get one digit from comp rcall asctohex ; convert received data to hex swap rreg ; swap nibbles mov datbyt,rreg ; copy rreg to data byte register rcall rxcomp ; get next digit from comp rcall asctohex add datbyt,rreg ret ; go to calling function ;***************************************************************************** ;'Transmit' ;Aim ; Transmit data to computer - 8 bits ;Registers used ; treg : contains data to be transmitted ; datbyt : contains packed hex data from calling function ;Functions called ; hextoasc ; txcomp ;***************************************************************************** transmit: mov treg,datbyt swap treg ; swap nibbles rcall hextoasc ; convert one digit to ASCII rcall txcomp ; and transmit mov treg,datbyt rcall hextoasc ; convert next digit to ASCII rcall txcomp ; and transmit ret ; return if complete data transmitted ;***************************************************************************** ;'hextoasc' ;Aim ; Convert hex to ASCII. Hex value is passed from & ASCII value is passed ; back to calling function in register treg. ;Registers used ; rtemp temporary register ; treg register containing data ;Functions called ; none ;***************************************************************************** hextoasc: andi treg,$0f cpi treg,$0a brsh henxt1 ldi rtemp,$30 rjmp henxt2 henxt1: ldi rtemp,$37 henxt2: add treg,rtemp ret ;***************************************************************************** ;'asctohex' ;Aim ; Convert ASCII to hex. ASCII value to be converted is passed from & hex ; value is passed back to calling function in register rreg. ;Registers used ; rreg register containing data ;Functions called ; none ;***************************************************************************** asctohex: cpi rreg,$40 brsh asnxt subi rreg,$30 rjmp asnxt1 asnxt: subi rreg,$37 asnxt1: ret ;***************************************************************************** ;'rxcomp' ;Aim ; Function to receive data (1 digit) from computer. Value received is ; passed to calling function through register rreg. ;Registers used ; rtemp temporary register ; rreg register containing data received ;Functions called ; none ;***************************************************************************** rxcomp: ldi rtemp,$10 ; Enable receiver out UCR,rtemp rxpoll: sbis USR,7 ; Poll to check if char received rjmp rxpoll in rreg,UDR ; Put received data in rreg ret ;***************************************************************************** ;'txcomp' ;Aim ; Function to transmit data (1 digit) to computer. The value to be ; transmitted is passed from calling function into register treg. ;Registers used ; rtemp temporary register ; treg register containing data to be transmitted ;Functions called ; none ;***************************************************************************** txcomp: ldi rtemp, $08 ; Enable transmitter out UCR,rtemp out UDR,treg txpoll: sbis USR,5 ; Poll to check end of transmission rjmp txpoll ret