Header Ads

How to latching LEDs use PIC Microcontroller and Mikro C


In this tutorial we will learn how to latch LED use pic microcntroller. Here I am use PIC16F877A and LM16x2 Lcd display. You can watch the video or read the written tutorial below.



Latch circuits output has tow stable state
  1. High state
  2. Low state
 When output High state than the Led is ON and Low state Led is OFF.





Latch ciruit



Circuit Schematic of Latch:





Mikro C Code :
// Lcd module connections
sbit LCD_RS at RB0_bit;
sbit LCD_EN at RB1_bit;
sbit LCD_D4 at RB2_bit;
sbit LCD_D5 at RB3_bit;
sbit LCD_D6 at RB4_bit;
sbit LCD_D7 at RB5_bit;
sbit LCD_RS_Direction at TRISB0_bit;
sbit LCD_EN_Direction at TRISB1_bit;
sbit LCD_D4_Direction at TRISB2_bit;
sbit LCD_D5_Direction at TRISB3_bit;
sbit LCD_D6_Direction at TRISB4_bit;
sbit LCD_D7_Direction at TRISB5_bit;
// End lcd module connnections
# define SW PORTD.RD7 // switch is connect to RD7
int i = 0;
void main() {
TRISC = 0X00; // PORTC in output
TRISD = 0X80; // RD7 is input
PORTC = 0X00; // clear PORTC
PORTD = 0X00; // Clear PORTD
Lcd_Init(); // Initialize Lcd module
Lcd_Cmd(_LCD_CURSOR_OFF); // Lcd cursor off
Lcd_Cmd(_LCD_CLEAR); // Led clear
Lcd_Out(1,3,"DEVELOPED BY"); // Lcd show "DEVELOPED BY"
Lcd_Out(2,1,"MINA TECHNOLOGY"); // Lcd show "MINA TECHNOLOGY"
delay_ms(2000); // 2s delay
Lcd_Cmd(_LCD_CLEAR); // Lcd clear
Lcd_Out(1,5,"LATCH"); // Lcd show "LATCH"
Lcd_Out(2,1,"LED:"); // Lcd show "LED:"
while(1){ // Endless loop
if(SW==0){
while(SW==0); // wait for SW release
i++; // Increase value
}
PORTC = i;
if(i==2)i=0;
if(i==0){
Lcd_Out(2,5,"OFF");
}
else{
Lcd_Out(2,5,"ON ");
}
}
}




Click the download for hex code and proteus simulation:
download

No comments

Theme images by 5ugarless. Powered by Blogger.