circuit contain PIC micrcontroller ,led,lcd,motor and bulb which are played by keybab
code Mikroc for pic micrcontroller :
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit; //above is initialize for LCD ,this is in help
char txt1[] = "Hello"; // string to display on LCD
char keypadPort at PORTC;
unsigned short kp;
void main()
{
TRISB.RB6 = 0;
TRISA = 0;
PORTA = 0;
PORTB.RB6 = 1;
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_Out(1,6,txt1);
while(1)
{
do
{
kp = Keypad_Key_Click();
} while(!kp);
if(kp == 1 )
{
}
else if(kp ==2)
{
PORTA.RA0 = 1; //Run bulb .
}
else if(kp == 3)
{
PORTA.RA1 = 1;//Run led
}
else if(kp == 4 )
{
PORTA.RA2 = 1;Run Motor.
}
else
{
PORTA = 0;
}
}
}
code Mikroc for pic micrcontroller :
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit; //above is initialize for LCD ,this is in help
char txt1[] = "Hello"; // string to display on LCD
char keypadPort at PORTC;
unsigned short kp;
void main()
{
TRISB.RB6 = 0;
TRISA = 0;
PORTA = 0;
PORTB.RB6 = 1;
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_Out(1,6,txt1);
while(1)
{
do
{
kp = Keypad_Key_Click();
} while(!kp);
if(kp == 1 )
{
}
else if(kp ==2)
{
PORTA.RA0 = 1; //Run bulb .
}
else if(kp == 3)
{
PORTA.RA1 = 1;//Run led
}
else if(kp == 4 )
{
PORTA.RA2 = 1;Run Motor.
}
else
{
PORTA = 0;
}
}
}
No comments:
Post a Comment