Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] How to blink a LED in PIC16F628A microcontroller

Status
Not open for further replies.

slaskar

Newbie level 6
Newbie level 6
Joined
Jun 20, 2013
Messages
12
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Visit site
Activity points
85
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:

You want to blink all of them at the same time? u can do like this:


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.

I am using MPLAB and i want the same to be written in assembly with an external crystal frequency oscillator of 20 Mhz

- - - Updated - - -

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.

I am using MPLAB and i want the same to be written in assembly with an external crystal frequency oscillator of 20 Mhz. Please tell me where i can get ideas about the configuration bits and control registers....
 

can anybody tell me the location of ADCON register in PIC 16F628A

- - - Updated - - -

IN PIC16F628A PORT A is associated with CMCON (LOCATION : 1Fh) ; VRCON (LOCATION : 9Fh) but i donn't think ADCON register is there in PIC16F628A

- - - Updated - - -

can you tell me the location of ADCON register in PIC 16F628A

- - - Updated - - -

IN PIC16F628A PORT A is associated with CMCON (LOCATION : 1Fh) ; VRCON (LOCATION : 9Fh) but i donn't think ADCON register is there in PIC16F628A

- - - Updated - - -

can you tell me the location of ADCON register in PIC 16F628A

- - - Updated - - -

IN PIC16F628A PORT A is associated with CMCON (LOCATION : 1Fh) ; VRCON (LOCATION : 9Fh) but i donn't think ADCON register is there in PIC16F628A
 

which version of mplab are you using?
Because configuration bits should be programmed using mplab only.
 

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

You can assign value ADCON1bits.ADON for enabling or disabling

You can find these registers in ADC module of your Data Sheet.

- - - Updated - - -

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

You can assign value ADCON1bits.ADON for enabling or disabling

You can find these registers in ADC module of your Data Sheet.

but why you want to disable ADC for LED's ??

a simple program
//************************************************** *************
void main(void) {
TRISA = 0; // set PortA as output
LATA = 1; // switch on LEDs

while(1) {
LATA = ~LATA // invert off to on & on to off
delay(2); // Delay for 2sec
}
}//end main

void delay(int t){
int i;
while(t--)
for (i = 0;i<1275; count++) // 1275 cycles approx 1ms
Nop(); // donthing.
}//end delay
 

I am using version 8.60 of MPLAB and here is my configuration

__CONFIG _CP_OFF & _DATA_CP_OFF & _LVP_OFF & _BOREN_OFF & _MCLRE_ON & _PWRTE_OFF & _HS_OSC

I am using external clock source with a frequency of 20 Mhz

- - - Updated - - -

I am using PIC16F628A where there is no ADCON REGISTER which are available in PIC 18 Series. I am not dealing with an analog signal therefore i want to disable it
 

Sorry friend. I check 16F628A & fond that it has no ADC but Comparator module so u should switch Off comparator CMCON = 0x07
 

Do i need to configure VRCON which is associated with PORTA

- - - Updated - - -

Here is the program the LEDs are glowing continously but not blinking
#include <P16F628A.INC>
__CONFIG _CP_OFF & _DATA_CP_OFF & _LVP_OFF & _BOREN_OFF & _MCLRE_ON & _PWRTE_OFF & _HS_OSC

MYREG EQU 1AH
ORG 0H
MOVLW 0X07
MOVWF CMCON
BCF STATUS, RP1
BSF STATUS, RP0
BCF TRISA, 0
BCF TRISA, 1
BCF TRISA, 2
BCF TRISA, 3
BACK BCF STATUS, RP0
BCF STATUS, RP1
BSF PORTA, 0
BSF PORTA, 1
BSF PORTA, 2
BSF PORTA, 3
CALL DELAY
BCF PORTA, 0
BCF PORTA, 1
BCF PORTA, 2
BCF PORTA, 3
CALL DELAY
GOTO BACK

;------ THIS IS THE DELAY SUBROUTINE

ORG 300H
DELAY MOVLW D'250'
MOVWF MYREG
AGAIN NOP
NOP
DECF MYREG, F
GOTO AGAIN
RETURN
END

- - - Updated - - -

i have modified the time delay loop and engaged the controller for 1 seconds but still not blinking
 

can anybody tell me just to blink only one LED connected to porta pin 2
 

My code is:

Code:
#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
;*****************************************************************************************************

You need to read the datasheet to know the commands!!!
 
Last edited:
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top