AT90S2313-SignalGenerator
This project shows the application of AT90S2313 as signal generator. This will
give you seven different types of signals with different pulse width. Giving
binary values on PD0-PD2 can numerically control the pulse width of the signal.
The signal can be obtained from the OC1 PIN of the AT90S2313 Microcontroller.
The program is as shown:
_SREG__ = 0x3f
__SP_H__ = 0x3e
__SP_L__ = 0x3d
__tmp_reg__ = 0
__zero_reg__ = 1
.global __do_copy_data
.global __do_clear_bss
.text
.global main
.type main, @function
;------------SIGNAL GENERATOR USING 90S2313-------
main:
ldi r25,0x00
out 0x18,r25 ;initializing PORTB
ldi r25,0X0F ;loading the low 4 bits of R25 with 1's
out 0X17,r25 ;setting the low bits of the ‘DDRB’ register as 1's
com r25 ;complementing the R25 register
ori r25,0b0001000
out 0X11,r25 ;setting the ‘DDRD’ register's low 3 bits in input mode
in r20,0X10 ;inputting the PORTD lower bit values on R20
;pulse width deciding factor
ldi r22,0xFA ;loading the initial value ,i.e. frequency decider
cpi r20,0x00
breq loop3
cpi r20,0x07
breq loop5
loop1:
dec r20 ;Decrementing the input values
brne loop2 ;moving to a loop where is actual frequency is decided
; pulse width delay
loop3:
ldi r16,0x00 ; initializing the 16 bit TCNTH1 & TCNTL1 registers
out 0X2C,r16
ldi r16,0x00
out 0X2D,r16
out 0X2A,r22 ; loading the output compare registers with
out 0X2B,r16 ; the values in the R22
ldi r18,0x40 ; setting the compare output mode bits for OC1 pin
out 0X2F,r18
out 0X39,r18 ; setting up TIMSK register
sei ;setting up the global interrupt enable bit
subi r18,0x20
out 0X35,r18 ; setting up the SE bit of MCUCR register
ldi r19,0x01
out 0X2E,r19 ;setting the TCCR1B register = clk/8
sleep
rjmp loop3
loop2:
lsr r22 ; Shifting R22 right
rjmp loop1
loop5:
ldi r22,0x01 ;routine for sequence '0111'
rjmp loop3
/*;--------------------------------------------------
;interrupt service routine for compare match timer 1
;----------------------------------------------------*/
.size main, .-main
.global __vector_4
.type __vector_4, @function
__vector_4:
ldi r28,0x00 ; Stopping the TIMER0
out 0x2E,r28
ret