Jon Chandler
Banned
Those are the "cut and paste" programmers 3v0. No effort to understand the code, just paste it in and be mystified when it doesn't work.
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
// blink LED on RA0
void delay(void)
{
int i = 1000; // i is a 16 bit integer value
LOOP2:
i = i - 1;
if (i > 0) goto LOOP2;
}
void main(void)
{
LATA=0xFE; // RA0 is output
LOOP1:
PORTAbits.RA0 = 0; // set RA0 to 0
delay(); // call delay
PORTAbits.RA0 = 1; // set RA0 to 1
delay(); // call delay
goto LOOP1;
}
me said:For the most part C code is what the author makes it. Anything for pure elegance to mud ugly.
Post your code. Without that, you'll get nothing, or wild guesses.
;Hello chip program, adapted from http://www.winpicprog.co.uk/pic_tutorial1.htm.
LIST p=16F628a ;tell assembler what chip we are using
include "P16F628A.INC" ;include the defaults for the chip
__config _BODEN_ON & _CP_OFF & _DATA_CP_OFF & _PWRTE_ON & _WDT_OFF & _LVP_OFF & _MCLRE_ON & _XT_OSC
cblock 0x20 ;start of general purpose registers
count1 ;used in delay routine
counta ;used in delay routine
countb ;used in delay routine
endc
org 0x0000 ;org sets the origin, 0x0000 for the 16F628,
;this is where the program starts running
movlw 0x07
movwf CMCON ;turn comparators off (make it like a 16F84)
bsf STATUS, RP0 ;select bank 1
movlw b'00000000' ;set PortB all outputs
movwf TRISB
movwf TRISA ;set PortA all outputs
bcf STATUS, RP0 ;select bank 0
Loop
movlw 0xff
movwf PORTA ;set all bits on
movwf PORTB
nop ;the nop's make up the time taken by the goto
nop ;giving a square wave output
call Delay ;this waits for a while!
movlw 0x00
movwf PORTA
movwf PORTB ;set all bits off
call Delay
goto Loop ;go back and do it again
Delay movlw d'250' ;delay 250 ms (4 MHz clock)
movwf count1
d1 movlw 0xC7
movwf counta
movlw 0x01
movwf countb
Delay_0
decfsz counta,f
goto $+2
decfsz countb,f
goto Delay_0
decfsz count1,f
goto d1
retlw 0x00
end
Code:__config _BODEN_ON & _CP_OFF & _DATA_CP_OFF & _PWRTE_ON & _WDT_OFF & _LVP_OFF & _MCLRE_ON [B]& _XT_OSC[/B]
You need INTRC oscillator mode if you don't have any external components.