slaskar
Newbie level 6
Can anybody help me to blink four LEDs connected to port A (RA0;RA1;RA2;RA3) with an interval of 2 seconds please explain the configuration bits and the control registers to do the job
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 may not be available in some browsers.
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 void delay2s(void); //*************************************************************** void main(void) { TRISA=0x00; // Outputs PortA OSCCON=0x76; //Configure internal oscillator while(1) // endless loop { LATA=0x0F // Switch on four LEDs delay2s(); // Delay for 2s LATA=~LATA //Switch off LEDs (toggle port) delay2s(); // Delay for 2s } }//end main //*************************************************************** *************************************************************** void delay2s(void){ int count; for (count = 0; count < 40; count++) { __delay_ms(50); } }//end delay2s
You can calculate your delay as per your requirement and according to your crystal frequency..
Go here,
**broken link removed**
and for blinking an led go to microchip tutorials for general i/o programming.
You can calculate your delay as per your requirement and according to your crystal frequency..
Go here,
**broken link removed**
and for blinking an led go to microchip tutorials for general i/o programming.
can anybody tell me the location of ADCON register in PIC 16F628A
IN PIC16F628A PORT A is associated with CMCON (LOCATION : 1Fh) ; VRCON (LOCATION : 9Fh) but i donn't think ADCON register is there in PIC16F628A
can anybody tell me the location of ADCON register in PIC 16F628A
IN PIC16F628A PORT A is associated with CMCON (LOCATION : 1Fh) ; VRCON (LOCATION : 9Fh) but i donn't think ADCON register is there in PIC16F628A
#INCLUDE <P16F628A.INC>
#DEFINE BANK0 BCF STATUS,RP0
#DEFINE BANK1 BSF STATUS,RP0
;*****************************************************************************************************************************************
__CONFIG _HS_OSC & _WDTE_OFF & _WDT_OFF & _PWRTE_OFF & _MCLRE_OFF & _BOREN_OFF & _LVP_OFF & _CPD_OFF & DATA_CP_OFF & _CP_OFF
;*****************************************************************************************************************************************
ERRORLEVEL -302
CBLOCK 0x20
TEMP1
TEMP2
TEMP3
ENDC
;*****************************************************************************************************
ORG 0X00
GOTO INICIO
;*****************************************************************************************************
ORG 0X04
INTSAI
NOP
RETFIE
;*****************************************************************************************************
INICIO
BANK0
CLRF PORTA
CLRF PORTB
MOVLW 0X07
MOVWF CMCON
BANK1
MOVLW B'00000000'
MOVWF TRISA
MOVLW B'00000000'
MOVWF TRISB
MOVLW B'10000000'
MOVWF OPTION_REG
BANK0
MOVLW 0
MOVWF PORTA
MOVWF PORTB
;*****************************************************************************************************
MAIN
BCF PORTA,3 ; this is pin 2 on IC (RA3) (Logical Level 0)
CALL DELAY2S
BSF PORTA,3 ;(Logical Level 1)
CALL DELAY2S
GOTO MAIN
;*****************************************************************************************************
; Delay = 2 seconds
; Clock frequency = 20 MHz
; Actual delay = 2 seconds = 10000000 cycles
; Error = 0 %
;*****************************************************************************************************
DELAY2S
;9999995 CYCLES
MOVLW 0X5A
MOVWF TEMP1
MOVLW 0XCD
MOVWF TEMP2
MOVLW 0X16
MOVWF TEMP3
LOOP_DELAY
DECFSZ TEMP1, F
GOTO $+2
DECFSZ TEMP2, F
GOTO $+2
DECFSZ TEMP3, F
GOTO LOOP_DELAY
;1 CYCLE
NOP
;4 CYCLES (INCLUDING CALL)
RETURN
;*****************************************************************************************************
END
;*****************************************************************************************************