Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

โครงงาน เครื่องคิดเลข

1,771 views

Published on

Published in: Business, Technology
  • Be the first to comment

โครงงาน เครื่องคิดเลข

  1. 1. MINI – KEY 4x4port 14 pin to 10 pin
  2. 2. HC11-CPU ET-EXP4
  3. 3. key switch connect MCS 51 and LCDShift = key switch = “ ” Shift = “ ” Shift sin = “ ” Shift cos
  4. 4. = “ ” Shift tan = “ ” Shift log = “ ” Shift sqrt = “ ” Shift epxp = “ ” Shift pow 28= “ ” Shift pow 39= “ ” Shift absolute+= “ ”- = “ ”*= “ ”/ = “ ”
  5. 5. key switch#include <at89c51xd2.h>#include <stdlib.h>#include <string.h>#include <stdio.h>#include <math.h>sbit E = P0^2;sbit RS = P0^0;sbit a1 = P1^0; //rowsbit a2 = P1^1;sbit a3 = P1^2;sbit a4 = P1^3;sbit b1 = P1^4; //colsbit b2 = P1^5;sbit b3 = P1^6;sbit b4 = P1^7;char keyp(){char nkey = ;
  6. 6. a1 = 0; a2 = 1; a3 = 1; a4 = 1;if(a1 == 0 && b1 == 0) nkey = 7;else if(a1 == 0 && b2 == 0) nkey = 4;else if(a1 == 0 && b3 == 0) nkey = 1;else if(a1 == 0 && b4 == 0) nkey = c;a1 = 1; a2 = 0; a3 = 1; a4 = 1;if(a2 == 0 && b1 == 0) nkey = 8;else if(a2 == 0 && b2 == 0) nkey = 5;else if(a2 == 0 && b3 == 0) nkey = 2;else if(a2 == 0 && b4 == 0) nkey = 0;a1 = 1; a2 = 1; a3 = 0; a4 = 1;if(a3 == 0 && b1 == 0) nkey = 9;else if(a3 == 0 && b2 == 0) nkey = 6;else if(a3 == 0 && b3 == 0) nkey = 3;else if(a3 == 0 && b4 == 0) nkey = =;a1 = 1; a2 = 1; a3 = 1; a4 = 0;if(a4 == 0 && b1 == 0) nkey = /;else if(a4 == 0 && b2 == 0) nkey = *;else if(a4 == 0 && b3 == 0) nkey = -;else if(a4 == 0 && b4 == 0) nkey = +;return nkey;}void delay(unsigned int count){unsigned int i;for(i=0;i<=count;i++);
  7. 7. }void write_data(unsigned char c){P0 = (c & 0xF0) | 0x01;E = 1; delay(200);E = 0; delay(200);P0 = ((c << 4) & 0xF0) | 0x01;E = 1; delay(200);E = 0; delay(200);}void write_init(unsigned char i){P0 = (i & 0xF0);E = 1; delay(200);E = 0; delay(200);P0 = ((i<<4) & 0xF0) ;E = 1; delay(200);E = 0; delay(200);}void write_string(unsigned char *s){unsigned short i, len;len = strlen(s);for(i = 0;i <= (len-1);i++){write_data(s[i]);}
  8. 8. }float cal (float f, float l, unsigned char o){float ans = 0;if(o == +) ans = f + l;else if(o == -) ans = f - l;else if(o == *) ans = f * l;else if(o == /) ans = f / l;else if(o == s) ans = sin(f);else if(o == c) ans = cos(f);else if(o == t) ans = tan(f);else if(o == l) ans = log(f);else if(o == q) ans = sqrt(f);else if(o == e) ans = exp(f);else if(o == p) ans = pow(2,l);else if(o == P) ans = pow(3,l);else if(o == S) ans = abs(f);return ans;}void main (){unsigned char keypad;unsigned char Fnum[7], Lnum[7], Ans[15];float fnum = 0, lnum = 0, ans = 0;unsigned char Oper = ;unsigned short countdigit = 0;unsigned short c, chkc = 1;write_init(0x33);
  9. 9. write_init(0x32);write_init(0x28);write_init(0x0e);write_init(0x01);write_init(0x0c); while(1) { keypad = keyp(); if(countdigit <= 5 && keypad >= 0 && keypad <= 9) { if(Oper == ) Fnum[countdigit] = keypad; else Lnum[countdigit] = keypad; write_data(keypad); countdigit++; }else if(keypad == +){Oper = +;write_data(+);countdigit = 0;}else if(keypad == -){Oper = -;write_data(-);countdigit = 0;}else if(keypad == *){
  10. 10. Oper = *;write_data(*);countdigit = 0;}else if(keypad == /){Oper = /;write_data(/);countdigit = 0;}else if(keypad == c){chkc = 1;while(chkc){keypad = keyp();if(keypad == 0){write_init(0x01);write_init(0x80);countdigit = 0;Oper = ;for(c = 0;c <= 14;c++){if(c<=7){Fnum[c] = ;Lnum[c] = ;}
  11. 11. Ans[c] = ;}chkc = 0;}else if(keypad == 1){Oper = s;write_string("sin ");chkc = 0;}else if(keypad == 2){Oper = c;write_string("cos ");chkc = 0;}else if(keypad == 3){Oper = t;write_string("tan ");chkc = 0;}else if(keypad == 4){Oper = l;write_string("log ");chkc = 0;}else if(keypad == 5)
  12. 12. {Oper = q;write_string("sqrt ");chkc = 0;}else if(keypad == 6){Oper = e;write_string("epxp ");chkc = 0;}else if(keypad == 7){Oper = p;write_string("power 2 ");chkc = 0;}else if(keypad == 8){Oper = P;write_string("power 3 ");chkc = 0;}else if(keypad == 9){Oper = S;write_string("absolute ");chkc = 0;while(keypad != )
  13. 13. {keypad = keyp();}}}else if(keypad == = && Oper != ){fnum = atof(Fnum);lnum = atof(Lnum);ans = cal(fnum,lnum,Oper);sprintf(Ans,"%0.3f",ans);write_init(0xC0);write_data(=);write_string(Ans);}while(keypad != ){keypad = keyp();}}}

×