;************************************************************
; written by: XXXXXXXXX *
; date: 1/14/2020 *
; version: 1.0 *
; file saved as: LED_Buzzer.asm *
; for PIC16F54 *
; clock frequency: 2.4576 MHz *
;***********************************************************
; PROGRAM FUNCTION: Turns on an LED on PoartA, and a Buzzer
; on PortB
;___________________________________________________________
#Include <p16f54.inc>
__CONFIG _OSC_XT & _WDT_OFF & _CP_OFF
;===========================================================
; Declarations:
porta equ 05
portb equ 06
Mark30 equ 07
Post80 equ 08
_5Second equ 09
org 1FFh
goto Start
org 0
;==========================================================
; Subroutines:
Init movlw b'00000111' ;set up TMR0 to count
option ;internally, prescaled by 256
clrf PORTA ; resets input/output ports
clrf PORTB
movlw b'00000' ; sets up which pins are inputs
tris PORTA ; and which are outputs
movlw b'00000000'
tris PORTB
retlw 0
;=========================================================
; Program Start:
Start
call Init
movlw d'30' ;moves the decimal number 30 into
movwf Mark30 ;the GPF called Mark30, the marker
movlw d'80' ;moves the decimal number 80 into
movwf Post80 ;the GPF called Post80, the first
;postcaler
movlw d'5' ;move the decimal number 5 into
movwf _5Second ;the GPF called _5Second
TimeLoop
movfw Mark30 ;takes the number out of Mark30
subwf TMR0,w ;subtracts this number from the
;number in TMR0, leaving the result
;in the working register (and leaving
;TMR0 unchanged)
btfss STATUS,Z ;test the zero flag-skip if set,i.e. if
;the result is zero it will skip the next
;instruction
goto TimeLoop ;if the result isn't zero, it loops back to
;'TimeLoop'
movlw d'30' ;moves the decimal number 30 into
addwf Mark30,f ;the working register and then
;adds it to Mark30
decfsz Post80,f ;decrements Post80, and skips the next
;instruction if the result is zero
goto TimeLoop ;if the result isn't zero, it loops back to
;'TimeLoop'
;When it reaches this point, 1 second
;has passed
movlw d'80' ;resets Post80, moving the number 80
movwf Post80 ;back into it
call LEDToggle
bcf PORTB,RB0 ;turns buzzer of
decfsz _5Second,f ;check if 5 seconds have pass and turns on
;Buzzer
call TurnBuzzer
goto TimeLoop
TurnBuzzer
bsf PORTB,RB0 ;turns buzzer on
movlw d'5' ;move the decimal number 5 into
movwf _5Second ;the GPF called _5Second
retlw 0x00
LEDToggle
movf PORTA,w ;Move PORTA to the working register
xorlw b'0001' ;Toggle bit RA0 from PORTA
movwf PORTA ;
retlw 0x00
END
I wrote a program in assembly to blink and LED on PortA bit0 every second and to turn on a buzzer. On PortB, bit0 beeps every 5 seconds nut once the buzzer activates it will produce a continuous tone.