In: Computer Science
Using P18f4580 controller - Write a program in C using Timer0 to generate a square wave with a frequency of 1kHz on PORTBRB5? (Assume XTAL = 20 MHz).
The P18f4580 PROGRAM TO GENERATE A SQUARE QAVE OF FREQUENCE 1KHZ ON PORTBR5 is given as follows:
----------------------------------------------------------------
Program:
#include <p18F458.inc>
ORG 0x00
GOTO START
ORG 0x30
START BCF TRISB,4
MOVLW 0x08
MOVWF T0CON
HERE MOVLW 0xFB
MOVWF TMR0H
MOVLW 0x1E
MOVWF TMR0L
BCF INTCON,TMR0IF
CALL DELAY
BTG PORTB,RB5
BRA HERE
DELAY BSF T0CON,TMR0ON
AGAIN BTFSS INTCON,TMR0IF
BRA AGAIN
BCF T0CON,TMR0ON
RETURN
END
----------------------------------------------------------
So, the program above generates a square wave on PORT RB5.
--------------------------------------Please Upvote-----------------------------------------------------------------------------------