วันจันทร์ที่ 14 มกราคม พ.ศ. 2562

T10




#line 1 "C:/Users/bunthit/Desktop/TEST 1/T10.c"
void main()
{
 unsigned char Dec,d1,d2,d3;
 unsigned char Bin[8];
 unsigned char keypad[]={0,1,2,3,0,
 4,5,6,0,
 7,8,9,0,
 0,0,0,0};
 unsigned int kp,i;
 TRISC=0;
 TRISD=0xFF;
 Lcd_Init(&PORTC);
 Keypad_Init(&PORTD);
 Lcd_Cmd(LCD_CURSOR_OFF);
 Return:Lcd_Cmd(LCD_CLEAR);
 Lcd_Out(1,1,"Dec>Bin Bin>Dec");
 Lcd_Out(2,1,"   1       2   ");
 while(Keypad_Read()!=1&&Keypad_Read()!=2);
 if(Keypad_Read()==1)goto DectoBin;
 if(Keypad_Read()==2)goto BintoDec;
 DectoBin:while(Keypad_Read());
 Lcd_Cmd(LCD_CLEAR);
 Lcd_Out(1,1,"Enter Dec");
 for(i=0;i<2;i++)
 {
 while(!Keypad_Read());
 kp=Keypad_Read();
 Dec=Dec*10*i+keypad[kp];
 Lcd_Chr(2,i+1,keypad[kp]+48);
 while(Keypad_Read());
 }
 Bin[0]=Dec%2;
 Bin[1]=(Dec/2)%2;
 Bin[2]=(Dec/4)%2;
 Bin[3]=(Dec/8)%2;
 Bin[4]=(Dec/16)%2;
 Bin[5]=(Dec/32)%2;
 Bin[6]=(Dec/64)%2;
 Bin[7]=(Dec/128)%2;
 while(Keypad_Read()!=15);
 Lcd_Cmd(LCD_CLEAR);
 Lcd_Out(1,1,"Bin");
 for(i=0;i<8;i++)
 {
 Lcd_Chr(2,i+1,Bin[7-i]+48);
 }
 while(Keypad_Read());
 while(Keypad_Read()!=15);
 goto Return;
 BintoDec:while(Keypad_Read());
 Lcd_Cmd(LCD_CLEAR);
 Lcd_Out(1,1,"Enter Bin");
 for(i=0;i<8;i++)
 {
 while(Keypad_Read()!=1&&Keypad_Read()!=14);
 kp=Keypad_Read();
 Bin[7-i]=keypad[kp];
 Lcd_Chr(2,i+1,Bin[7-i]+48);
 while(Keypad_Read());
 }
 Dec=Bin[0];
 Dec=Dec+Bin[1]*2;
 Dec=Dec+Bin[2]*4;
 Dec=Dec+Bin[3]*8;
 Dec=Dec+Bin[4]*16;
 Dec=Dec+Bin[5]*32;
 Dec=Dec+Bin[6]*64;
 Dec=Dec+Bin[7]*128;
 d1=Dec/100;
 d2=(Dec%100)/10;
 d3=Dec%10;
 while(Keypad_Read()!=15);
 Lcd_Cmd(LCD_CLEAR);
 Lcd_Out(1,1,"Dec");
 Lcd_Chr(2,1,d1+48);
 Lcd_Chr(2,2,d2+48);
 Lcd_Chr(2,3,d3+48);
 while(Keypad_Read());
 while(Keypad_Read()!=15);
 goto Return;
}

ไม่มีความคิดเห็น:

แสดงความคิดเห็น