Skip to content

Instantly share code, notes, and snippets.

@faraazahmad
Created February 27, 2019 06:45
Show Gist options
  • Save faraazahmad/9305e3fdc456008d3caeed4622785ac0 to your computer and use it in GitHub Desktop.
Save faraazahmad/9305e3fdc456008d3caeed4622785ac0 to your computer and use it in GitHub Desktop.
lcd switch counter
#include <LCD.h>
sbit l1 = P3^0;
sbit l2 = P3^1;
sbit s1 = P3^2;
sbit s2 = P3^3;
sbit s4 = P3^5;
void counter_3(){
char* arr[] = {"000", "001", "010", "011", "100", "101", "110", "111"};
int i;
for(i=0;i<8;i++){
LCD_WRITE(arr[i], 0, 0);
delay(1000);
LCD_CMD(LCD_CLEAR);
}
}
void counter_2(){
char* arr[] = {"00", "01", "10", "11"};
int i;
for(i=0;i<4;i++){
LCD_WRITE(arr[i], 0, 0);
delay(1000);
LCD_CMD(LCD_CLEAR);
}
}
void counter_1(){
char* arr[] = {"0", "1"};
int i;
for(i=0;i<2;i++){
LCD_WRITE(arr[i], 0, 0);
delay(1000);
LCD_CMD(LCD_CLEAR);
}
}
void main() {
s1 = s2 = s4 = l1 = l2 = 1;
LCD_INIT();
LCD_CMD(LCD_CLEAR);
while(1){
if(s1==1 && s2==0){
l1 = 1;
l2 = 0;
if (s4 == 0)
counter_1();
}
else if(s1==0 && s2==1){
l1 = 0;
l2 = 1;
if (s4 == 0)
counter_2();
}
else if(s1==0 && s2==0){
l1 = 0;
l2 = 0;
if (s4 == 0)
counter_3();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment