500Kz square wave from pic18f65k22 using xc8 c compiler?

Status
Not open for further replies.
Use the simulator or hardware. It was not possible tell the exact timimg of C code. And also the dutycycle will not be 50% for your #13 code.
 
Reactions: treez

    T

    Points: 2
    Helpful Answer Positive Rating
thanks, I don't need the duty to be exactly 50 percent.....as long as no mark or space is less than 2us.
 

Code:
L1:	MOVLW 0x40
	MOVWF 0x022   ; Initially Load 64 to a register in start
L2:	BCF PORTC,5
	BSF PORTC,5
	DECFSZ 0x022,F
	GOTO L2                ;5  instruction cycles in a period
	BCF PORTC,5     ; 64 pulses completed
	MOVLW 0x40   ;Reload 64 in the register
	MOVWF 0x022
This assembly code generates 200KHz on PortC.5
 

Attachments

  • 64pulses.rar
    291.3 KB · Views: 119

Thanks, though if you see the compiler manual for XC8...doing inline assembler is horrifically complicated....there are all kinds of commands that you have to preceed it with, and its difficult to know which particular commands are needed for which particular case...and you cannot choose a register (0x022) for the count because the compiler may have chosen that register for some other variable, and you could overwrite it.
 

cannot choose a register
0x22 is just an example You can name a variable in C and then put its name in assembly. For example if you write in start R64=64. C will assign a register for variable R64 with value of 64. This equals L1 in assembly. Now look for the corresponding name of the register in asm file. It will be slightly different Use this name in assembly code.
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…