PIC16a84f
Task 1: Create a 1 Hz Square Waveform on PORT.A0
Write an assembly language program to create a 1 Hz square waveform on PORT A0.
a) First write your code to toggle PORT A0 without any delay
b) Then add a delay subroutine to produce the required delay. You are not allowed to use
Timer Interrupt for the delay subroutine.
I keep getting an error about my delay but i tried may ways and still wrong
Task 2: Up/Down Counter on PORT A
The goal of this task is to write an assembly code which can count every 1 second from 0000
to 1111 or in reverse order from 1001 to 0000 based on the 2 inputs RA0 and RA1 shown in
the Table 1. When the counting has reaches maximum (1111 for count up) or minimum (0000
for count down), the counting will loop back to the other end (start from 0000 again for count
up, or start from 1111 again for count down). The 4-bit output of the counting should be sent
to outputs RB7:4, where RB7 as MSB and RB4 as LSB.
for this one i cant count up or down , during pause it works
Code for task 1:
__CONFIG _CONFIG1, _FOSC_HS & _WDTE_OFF & _PWRTE_ON & _PWRTE_OFF & _BOREN_ON & _LVP_OFF & _CPD_OFF & _WRT_OFF & _DEBUG_OFF
__CONFIG _CONFIG2, _CP_OFF
START:
bcf STATUS, RP0 ; Select Bank 0
clrf PORTB ; Clear PORTB
movlw 0x00 ; Initialize PORTB to 0
movwf PORTB
movlw b’00001111′ ; Set RB7:4 as outputs, RB3:0 as inputs
movwf TRISB
movlw b’11111100′ ; Set RA0 and RA1 as inputs
movwf TRISA
MainLoop:
btfsc PORTA, 1 ; Check if RA1 is low (counter disable)
goto MainLoop ; If RA1 is low, do nothing
btfsc PORTA, 0 ; Check if RA0 is low (count down)
goto CountDown
goto CountUp
CountUp:
call Delay1Sec ; Wait for 1 second
incf PORTB, F ; Increment PORTB
movf PORTB, W
andlw b’11110000′ ; Mask the lower 4 bits
xorlw b’11110000′ ; Check if it is 1111
btfss STATUS, Z ; If it is not 1111, skip the next line
movlw b’00000000′ ; Reset to 0000 if it was 1111
movwf PORTB
goto MainLoop
CountDown:
call Delay1Sec ; Wait for 1 second
decf PORTB, F ; Decrement PORTB
movf PORTB, W
andlw b’11110000′ ; Mask the lower 4 bits
btfsc STATUS, Z ; If result is not 0000, skip the next line
movlw b’11110000′ ; Set to 1111 if it was 0000
movwf PORTB
goto MainLoop
Delay1Sec:
; Implement a delay here that approximates 1 second
; This delay loop is just a placeholder and should be calibrated
movlw D’255′
movwf count1
OuterDelayLoop:
movlw D’255′
movwf count2
InnerDelayLoop:
decfsz count2, f
goto InnerDelayLoop
decfsz count1, f
goto OuterDelayLoop
return
END
code for task 2:
ORG 0x00
goto START
ORG 0x04 ; Interrupt vector
START:
bcf STATUS, RP0 ; Select Bank 0
clrf PORTB ; Clear PORTB
movlw 0x00 ; Initialize PORTB to 0
movwf PORTB
movlw b’00001111′ ; Set RB7:4 as outputs, RB3:0 as inputs
movwf TRISB
movlw b’11111100′ ; Set RA0 and RA1 as inputs
movwf TRISA
MainLoop:
btfsc PORTA, 1 ; Check if RA1 is low (counter disable)
goto MainLoop ; If RA1 is low, do nothing
btfsc PORTA, 0 ; Check if RA0 is low (count down)
goto CountDown
goto CountUp
CountUp:
call Delay1Sec ; Wait for 1 second
incf PORTB, F ; Increment PORTB
movf PORTB, W
andlw b’11110000′ ; Mask the lower 4 bits
xorlw b’11110000′ ; Check if it is 1111
btfss STATUS, Z ; If it is not 1111, skip the next line
movlw b’00000000′ ; Reset to 0000 if it was 1111
movwf PORTB
goto MainLoop
CountDown:
call Delay1Sec ; Wait for 1 second
decf PORTB, F ; Decrement PORTB
movf PORTB, W
andlw b’11110000′ ; Mask the lower 4 bits
btfsc STATUS, Z ; If result is not 0000, skip the next line
movlw b’11110000′ ; Set to 1111 if it was 0000
movwf PORTB
goto MainLoop
Delay1Sec:
; Implement a delay here that approximates 1 second
; This delay loop is just a placeholder and should be calibrated
movlw D’255′
movwf count1
OuterDelayLoop:
movlw D’255′
movwf count2
InnerDelayLoop:
decfsz count2, f
goto InnerDelayLoop
decfsz count1, f
goto OuterDelayLoop
return
END
task 1 : a 1 Hz Square Waveform on PORT.A0
task 2 : Table 1(https://i.sstatic.net/UmUhy95E.png)
user25136115 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.