Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <reg515.sfr>
- #include <lcd.h>
- int a;
- int b;
- int state;
- char buff[24];
- void print(const char *str){
- //out_instr(1);
- while(*str){
- out_char(*str++);
- }
- }
- void sleep(){
- int t;
- int i;
- t = 20000;
- for(i=0;i<t;i++);
- }
- char * itoa(int s){
- int x;
- char *buffPos;
- buff[23] = '\0';
- buffPos = buff + 22;
- while(s != 0){
- x = s % 10;
- s /= 10;
- *buffPos-- = x + '0';
- }
- return buffPos + 1;
- }
- void main(){
- int x;
- int c;
- char *str;
- a = 0;
- b = 0;
- state = 0;
- sleep();
- lcd_init();
- sleep();
- out_instr(1);
- sleep();
- //print("Hello");
- while(1){
- unsigned char z = get_kb();
- if( z != '\0' ){
- if( z >= '0' && z <= '9'){
- x = z - '0';
- if(state){//liczba b
- b = b * 10 + x;
- }else{//liczba a
- a = a * 10 + x;
- }
- out_char(z);
- }else{
- switch(state){
- case 0: {
- state = 1;
- out_char('+');
- break;
- }
- case 1: {
- state = 2;
- out_char('=');
- c = a + b;
- //out_char(c);
- str = itoa(c);
- out_instr(1);
- print(str);
- break;
- }
- case 2: {
- state = 0;
- a = 0;
- b = 0;
- out_instr(1);
- break;
- }
- }
- /*
- if(state){
- state = 0;
- int c = a + b;
- char *str = itoa(c);
- print(str);
- }else{
- state = 1;
- out_char('+');
- }
- */
- }
- }
- sleep();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement