I have a pic18f45k20 chip and i am using mplax with c8 compiler and was wondering if any one can help me to construct a c code to create a 5khz frequency i habe done in using assembly but i am not familiar with c.
here is my asm code:
;//** I N C L U D E S ******************************/
list p=18f45k20
#include p18f45k20.inc
;//** C O N F I G U R A T I O N B I T S ***********/
CONFIG FOSC = INTIO67 ; INTIO67 Note that if it is HS it will not work!
CONFIG LVP = OFF
CONFIG PWRT = ON
CONFIG FCMEN = OFF
CONFIG IESO = OFF ;// CONFIG1H
CONFIG BOREN = SBORDIS
CONFIG BORV = 30 ;// CONFIG2L
CONFIG WDTEN = OFF
CONFIG WDTPS = 32768 ;// CONFIG2H
CONFIG MCLRE = OFF
CONFIG LPT1OSC = OFF
CONFIG PBADEN = ON
CONFIG CCP2MX = PORTC ;// CONFIG3H
CONFIG STVREN = ON
;
CONFIG XINST = OFF ;// CONFIG4L
CONFIG CP0 = OFF
CONFIG CP1 = OFF
CONFIG CP2 = OFF
CONFIG CP3 = OFF ;// CONFIG5L
CONFIG CPB = OFF
CONFIG CPD = OFF ;// CONFIG5H
CONFIG WRT0 = OFF
CONFIG WRT1 = OFF
CONFIG WRT2 = OFF
CONFIG WRT3 = OFF ;// CONFIG6L
CONFIG WRTB = OFF
CONFIG WRTC = OFF
CONFIG WRTD = OFF ;// CONFIG6H
CONFIG EBTR0 = OFF
CONFIG EBTR1 = OFF
CONFIG EBTR2 = OFF
CONFIG EBTR3 = OFF ;// CONFIG7L
CONFIG EBTRB = OFF
;---------------------------------
;Title: "Lab 5; 5kHz Blinking LED"
;---------------------------------
;Program Detail: This program will create a square wave
;at 5kHz that will correlate to the frequency of a blinking
;LED on the microchip.
;----------------------------------------------------------
;Purpose: Blink LED at a 5kHz frequency
;----------------------------------------------------------
;//** INITIALIZATION **//
count equ D'6' ;Variable used for counter
;//Register Declaration:/
reg1 equ 0x01 ;Register Declarations
reg10 equ 0x10
;//M A I N C O D E://
org 0x20
start
movlw b'00000000' ;Set up all bits in PORT D for
movwf TRISD ;output
movwf reg1
onoff
movff reg1,PORTD ;Turn on/off all bits in PORTD
movlw count ;Load counter in W and set up
movwf reg10 ;in reg10
delay
decf reg10,1 ;Decrement reg10 and repeat
bnz delay ;if reg10 is not equal to 0
comf reg1,1 ;Complement bit pattern for
bra onoff ;on/off
end