In: Electrical Engineering
question#1: Write instructions to toggle bits Bit0 of PORTB assuming the PORTB is already initialized as an output port.
question#2: The following unsigned integer readings are stored in data register starting from REG10 (address 10H). Data (H): 40, 45, 4A, 32, 52, 38, 3A, 44 Write a program that finds the average temperature. Simulate your program in PIC18 IDE Simulator and attach a screenshot of your simulation while the program is running.
STATUS equ 03h ;Address of the STATUS register
TRISB equ 86h ;Address of the tristate register for port B
PORTB equ 06h ;Address of Port B
COUNT1 equ 08h ;First counter for our delay loops
COUNT2 equ 09h ;Second counter for our delay loops
;****Set up the port****
bsf                  
STATUS,5       ;Switch to Bank
1                        
movlw 00h ;Set the Port A pins
movwf TRISB ;to output.
bcf STATUS,5 ;Switch back to Bank 0
;****Turn the LED on****
Start   
movlw              
01h                  
;Turn the LED on by first
putting                        
movwf PORTB ;it into the w register and then on the port
;****Start of the delay loop 1****
Loop1    decfsz
COUNT1,1       ;Subtract 1 from
255                     
goto Loop1 ;If COUNT is zero, carry on.
decfsz COUNT2,1 ;Subtract 1 from 255
goto Loop1 ;Go back to the start of our loop.
;This delay counts down from 255 to zero, 255 times
;****Delay finished, now turn the LED off****
  
movlw             
00h                    
;Turn the LED off by first
putting                    
movwf PORTB ;it into the w register and then on the port
;****Add another delay****
Loop2       
decfsz COUNT1,1 ;This second loop keeps the
goto Loop2 ;LED turned off long enough for
decfsz COUNT2,1 ;us to see it turned off
goto Loop2 ;
;****Now go back to the start of the program
  
goto                
Start                      
;go back to Start and turn LED on again
;****End of the program****
   end    ;Needed by some compilers, and also
just in case we miss the goto instruction.