NEW DATABASE - 350 MILLION DATASHEETS FROM 8500 MANUFACTURERS
HT45R36 HA0119E - Datasheet Archive
Using the HT45R36 I/O for Buzzer Driving D/N: HA0119E Introduction Some MCU devices do not possess a PFD function, however their
Using the HT45R36 HT45R36 I/O for Buzzer Driving Using the HT45R36 HT45R36 I/O for Buzzer Driving D/N: HA0119E HA0119E Introduction Some MCU devices do not possess a PFD function, however their applications may require a buzzer function. Therefore this application will use the HT45R36 HT45R36 as an example to show how a normal I/O pin can be used to simulate a PFD function and to drive a buzzer at a frequency of 2kHz. Application Circuit Connect a buzzer directly between the I/O pin PA3 and ground. By setting up the pin as an input or output the on/off function of the buzzer can be controlled. V D D 0 6 " # 4 ! $ V D D S p e a k e r 1 0 0 k W P A 3 R E S 1 0 k W 0 .1 m F V S S 2 M H z O S C 1 O S C 2 1 Using the HT45R36 HT45R36 I/O for Buzzer Driving Software Description .listinclude INCLUDE HT45R36 HT45R36.INC ;* DATA_MAIN .SECTION 'DATA' ;define data registers R_ACC_BAK DB ? ;accumulator backup R_STATUS_BAK DB ? ;status backup R_COUNTER1 DB ? ;Counter 1 R_COUNTER2 DB ? ;Counter 2 F_HALFSECOND DBIT ;0.5s status register ;-CODE_MAIN .SECTION AT 00H 'CODE';Program Section JMP MLP_MAIN ORG 04H ;Interrupt 0 entry point RETI ORG 08H ;Interrupt 1 entry point RETI ORG 0CH ;Timer/Event counter entry point JMP ISR_TIMER ;jump to timer routine ORG 10H ;RC oscillator entry point RETI ISR_TIMER: MOV R_ACC_BAK,A MOV A,STATUS MOV R_STATUS_BAK,A MOV A,08H XORM A,PA INC R_COUNTER1 MOV A,R_COUNTER1 XOR A,80 SNZ Z JMP L_EXIT_ISR_TIMER CLR R_COUNTER1 INC R_COUNTER2 MOV A,R_COUNTER2 XOR A,50 SNZ Z JMP L_EXIT_ISR_TIMER CLR R_COUNTER1 CLR R_COUNTER2 SZ F_HALFSECOND JMP L_CLRFLAG SET F_HALFSECOND JMP L_EXIT_ISR_TIMER L_CLRFLAG: CLR F_HALFSECOND ;Timer routine ;backup accumulator ;backup status register ;PA3 output inverted ;increase interrupt counts by 1 ;is time up80*125us=10ms? ;not yet at 10ms, exit interrupt ;time up, clear timer ;if up to 10ms increment this register ;is time up50*10ms=0.5s? ;not yet at 0.5s, exit interrupt ;time up, clear timer ;time up, clear timer ;check 0.5s flag ;0.5s flag is set, jump to clear 0.5S flag ;set 0.5s flag ;exit interrupt ;clear 0.5s flag 2 Using the HT45R36 HT45R36 I/O for Buzzer Driving L_EXIT_ISR_TIMER: MOV A,R_STATUS_BAK MOV STATUS,A MOV A,R_ACC_BAK RETI MLP_MAIN: MOV A,09H MOV INTC0,A CLR F_HALFSECOND CLR R_COUNTER1 CLR R_COUNTER2 MOV A,06H MOV TMR,A MOV MOV ;restore status register ;restore accumulator ; ;enable timer interrupt ;initialise 0.5s flag ;initialise timer register 1 ;set PA3 as an output, close PFD ;set timer initial value to 6, count ; to 250 and generate interrupt A,91H TMRC,A ;setup internal timer, ;division ratio MHz/2=1MHz ;every 250us generate an interrupt LOOP: SZ F_HALFSECOND JMP L_PFDOPEN L_PFDCLOSE: SET PAC.3 JMP LOOP L_PFDOPEN: CLR PAC.3 JMP LOOP ;check 0.5s flag set ;if set jump to start PFD ;if not set set PA3 as input and stop PFD ;cycle check output is PFD ;if yes, set PA3 as output and start PFD ;cycle check if output is PFD Software Description This program function will emit a sound every 0.5s for a time period of 0.5s. The program uses an interrupt period of 250us and uses the PA3 output. PA3 will emit a frequency of 2kHz and dirve a buzzer. Until PA3 is setup as an output, PA3 has not way to drive the buzzer and therefore the buzzer will stop emitting sounds. The program uses the Timer/Event Counter R_COUNTER1R_COUNTER2 to setup a time of 0.5s. When a 0.5s time has elapsed, the 0.5s time flag will invert, which will in turn cycle the on/off function of the buzzer. 3