fonddeath55
New Member
Can anyone give me a code to flash an led in mplab. that works with hex. And if not but you have an led code that works with somthing else can you tell me how it works.
Last edited:
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature currently requires accessing the site using the built-in Safari browser.
;************************************************* ***********
; Processor: PIC12F683 at 4 MHz using intosc
;************************************************* ***********
#include "P12F683.INC"
;
__config _FCMEN_OFF & _IESO_OFF & _PWRTE_OFF & _BOD_OFF & _MCLRE_OFF & _WDT_OFF & _CP_OFF & _CPD_OFF & _INTOSCIO
;
cblock 0x20
del1
del2
endc
org 0x00
clrf GPIO ;initialise all outputs
clrf CMCON0 ; CMCON0 set GP0, GP1 to analog input, GP2 to I/O and
banksel 0x80 ;select upper register bank
movlw 0x2f
movwf TRISIO ;make GP4 output
banksel 0x00 ;select lower register bank
Loop
bsf GPIO,4 ;set output GP4 high
call delay ;call the delay subroutine
bcf GPIO,4 ;set output GP4 low
call delay ;call the delay subroutine
goto Loop ;go back and do it again
delay
decfsz del1,f ;decrement the low order delay register
goto delay ;go back if it hasn't reached zero
decfsz del2,f ;decrement the high order delay register
goto delay ;go back if it hasn't reached zero
return ;return to where the subroutine was called
end
how does?I think this will do it,
Code:;************************************************* *********** ; Processor: PIC12F683 at 4 MHz using intosc ;************************************************* *********** #include "P12F683.INC" ; __config _FCMEN_OFF & _IESO_OFF & _PWRTE_OFF & _BOD_OFF & _MCLRE_OFF & _WDT_OFF & _CP_OFF & _CPD_OFF & _INTOSCIO ; cblock 0x20 del1 del2 endc org 0x00 clrf GPIO ;initialise all outputs clrf CMCON0 ; CMCON0 set GP0, GP1 to analog input, GP2 to I/O and banksel 0x80 ;select upper register bank movlw 0x2f movwf TRISIO ;make GP4 output banksel 0x00 ;select lower register bank Loop bsf GPIO,4 ;set output GP4 high call delay ;call the delay subroutine bcf GPIO,4 ;set output GP4 low call delay ;call the delay subroutine goto Loop ;go back and do it again delay decfsz del1,f ;decrement the low order delay register goto delay ;go back if it hasn't reached zero decfsz del2,f ;decrement the high order delay register goto delay ;go back if it hasn't reached zero return ;return to where the subroutine was called end
I think this was posted here some time ago.
Mike.
;************************************************* ***********
; Processor: PIC12F683 at 4 MHz using intosc
;************************************************* ***********
#include "P12F683.INC"
;
__config _FCMEN_OFF & _IESO_OFF & _PWRTE_OFF & _BOD_OFF & _MCLRE_OFF & _WDT_OFF & _CP_OFF & _CPD_OFF & _INTOSCIO
;
cblock 0x20
del1
del2
endc
org 0x00
clrf GPIO ;initialise all outputs
clrf CMCON0 ; CMCON0 set GP0, GP1 to analog input, GP2 to I/O and
banksel 0x80 ;select upper register bank
movlw 0xef
movwf TRISIO ;make GP4 output
banksel 0x00 ;select lower register bank
Loop
bsf GPIO,0 ;set output GP0 high
call delay ;call the delay subroutine
bcf GPIO,0 ;set output GP0 low
call delay ;call the delay subroutine
goto Loop ;go back and do it again
delay
decfsz del1,f ;decrement the low order delay register
goto delay ;go back if it hasn't reached zero
decfsz del2,f ;decrement the high order delay register
goto delay ;go back if it hasn't reached zero
return ;return to where the subroutine was called
end
;************************************************* ***********
; Processor: PIC12F683 at 4 MHz using intosc
;************************************************* ***********
#include "P12F683.INC"
;
__config _FCMEN_OFF & _IESO_OFF & _PWRTE_OFF & _BOD_OFF & _MCLRE_OFF & _WDT_OFF & _CP_OFF & _CPD_OFF & _INTOSCIO
;
cblock 0x20
del1
del2
endc
org 0x00
clrf GPIO ;initialise all outputs
movlw 7
movwf CMCON0
BANKSEL ANSEL ;
CLRF ANSEL ;digital I/O
banksel TRISO ;select upper register bank
movlw b'00000000'
movwf TRISIO ;setall output
banksel GPIO ;select lower register bank
movlw b'00000000';set all low
movwf GPIO
Loop
bsf GPIO,0 ;set output GP0 high
call delay ;call the delay subroutine
bcf GPIO,0 ;set output GP0 low
call delay ;call the delay subroutine
goto Loop ;go back and do it again
delay
decfsz del1,f ;decrement the low order delay register
goto delay ;go back if it hasn't reached zero
decfsz del2,f ;decrement the high order delay register
goto delay ;go back if it hasn't reached zero
return ;return to where the subroutine was called
end
;************************************************* ***********
; Processor: PIC12F683 at 4 MHz using intosc
;************************************************* ***********
#include "P12F683.INC"
;
__config _FCMEN_OFF & _IESO_OFF & _PWRTE_OFF & _BOD_OFF & _MCLRE_OFF & _WDT_OFF & _CP_OFF & _CPD_OFF & _INTOSCIO
;
cblock 0x20
del1
del2
endc
org 0x00
clrf GPIO ;initialise all outputs
movlw 7
movwf CMCON0 ; CMCON0 set GP0, GP1 to analog input, GP2 to I/O and
banksel 0x80 ;select upper register bank
clrf ANSEL
movlw 0xfe
movwf TRISIO ;make GP4 output
banksel 0x00 ;select lower register bank
Loop
bsf GPIO,0 ;set output GP4 high
call delay ;call the delay subroutine
bcf GPIO,0 ;set output GP4 low
call delay ;call the delay subroutine
goto Loop ;go back and do it again
delay
decfsz del1,f ;decrement the low order delay register
goto delay ;go back if it hasn't reached zero
decfsz del2,f ;decrement the high order delay register
goto delay ;go back if it hasn't reached zero
return ;return to where the subroutine was called
end
before it and
;************************************************* ***********
; Processor: PIC12F683 at 4 MHz using intosc
;************************************************* ***********
#include "P12F683.INC"
;
__config _FCMEN_OFF & _IESO_OFF & _PWRTE_OFF & _BOD_OFF & _MCLRE_OFF & _WDT_OFF & _CP_OFF & _CPD_OFF & _INTOSCIO
;
cblock 0x20
del1
del2
endc
org 0x00
clrf GPIO ;initialise all outputs
clrf CMCON0 ; CMCON0 set GP0, GP1 to analog input, GP2 to I/O and
banksel 0x80 ;select upper register bank
movlw 0x01
movwf TRISIO ;make GP4 output
banksel 0x00 ;select lower register bank
Loop
Bsf GPIO,1 ;led on
;into the w register and then on the port
;****Check if the switch is closed
BTFSC 9AH,0 ;Get the value from PORT A
;BIT 0. If it is a zero
call delay ;a zero, carry on as normal.
;If is is a 1, then add an
;extra delay routine
;****Add a delay
call delay
;****Delay finished, now turn the LED off****
Bsf GPIO,1
;****Check if the switch is still closed
BTFSC 9AH,0 ;Get the value from PORT A
;BIT 0. If it is a zero,
call delay ;carry on as normal.
;If is a 1, then add an
;extra delay routine
;****Add another delay****
call delay
;****Now go back to the start of the program
goto Loop ;go back to Start and turn LED on again
delay
decfsz del1,f ;decrement the low order delay register
goto delay ;go back if it hasn't reached zero
decfsz del2,f ;decrement the high order delay register
goto delay ;go back if it hasn't reached zero
return ;return to where the subroutine was called
end
clrf GPIO ;initialise all outputs
movlw 7
movwf CMCON0 ;CMCON0 set all digital
banksel 0x80 ;select upper register bank
clrf ANSEL
movlw 0x2f
movwf TRISIO ;make GP4 output
bsf WPU,0 ;turn on Weak pull up
banksel 0x00 ;select lower register bank
Loop btfss GPIO,0
bcf GPIO,4
btfsc GPIO,0
bsf GPIO,4
goto Loop