たけし みわ
/
y_HM55B
main.cpp@0:b28daf92293e, 2012-06-17 (annotated)
- Committer:
- esmiwa
- Date:
- Sun Jun 17 01:16:11 2012 +0000
- Revision:
- 0:b28daf92293e
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
esmiwa | 0:b28daf92293e | 1 | #include "mbed.h" |
esmiwa | 0:b28daf92293e | 2 | #include "TextLCD.h" |
esmiwa | 0:b28daf92293e | 3 | |
esmiwa | 0:b28daf92293e | 4 | #define High 1 |
esmiwa | 0:b28daf92293e | 5 | #define Low 0 |
esmiwa | 0:b28daf92293e | 6 | |
esmiwa | 0:b28daf92293e | 7 | DigitalInOut D(p15); |
esmiwa | 0:b28daf92293e | 8 | DigitalOut Csb(p16); |
esmiwa | 0:b28daf92293e | 9 | DigitalOut Clk(p17); |
esmiwa | 0:b28daf92293e | 10 | |
esmiwa | 0:b28daf92293e | 11 | DigitalOut myled1(LED1); |
esmiwa | 0:b28daf92293e | 12 | DigitalOut myled4(LED4); |
esmiwa | 0:b28daf92293e | 13 | |
esmiwa | 0:b28daf92293e | 14 | TextLCD lcd(p24, p26, p27, p28, p29, p30); // rs, e, d4-d7 |
esmiwa | 0:b28daf92293e | 15 | |
esmiwa | 0:b28daf92293e | 16 | int flag; //1100 flag data |
esmiwa | 0:b28daf92293e | 17 | int i; //counter |
esmiwa | 0:b28daf92293e | 18 | |
esmiwa | 0:b28daf92293e | 19 | int x; //X |
esmiwa | 0:b28daf92293e | 20 | int y; //Y |
esmiwa | 0:b28daf92293e | 21 | |
esmiwa | 0:b28daf92293e | 22 | //clock out |
esmiwa | 0:b28daf92293e | 23 | void CLK (char a) |
esmiwa | 0:b28daf92293e | 24 | { |
esmiwa | 0:b28daf92293e | 25 | Clk=a; |
esmiwa | 0:b28daf92293e | 26 | myled1=a; |
esmiwa | 0:b28daf92293e | 27 | wait_ms(1); |
esmiwa | 0:b28daf92293e | 28 | } |
esmiwa | 0:b28daf92293e | 29 | //4bit flag reaD.intput()g |
esmiwa | 0:b28daf92293e | 30 | int READ_FLAG () |
esmiwa | 0:b28daf92293e | 31 | { |
esmiwa | 0:b28daf92293e | 32 | flag=0; |
esmiwa | 0:b28daf92293e | 33 | D.input(); |
esmiwa | 0:b28daf92293e | 34 | for(i=0;i<4;i++){ |
esmiwa | 0:b28daf92293e | 35 | CLK(High);CLK(Low); //clock down edge |
esmiwa | 0:b28daf92293e | 36 | flag=flag*10; |
esmiwa | 0:b28daf92293e | 37 | flag=flag+D; //1100 flag reaD.intput()g |
esmiwa | 0:b28daf92293e | 38 | } |
esmiwa | 0:b28daf92293e | 39 | return flag; |
esmiwa | 0:b28daf92293e | 40 | } |
esmiwa | 0:b28daf92293e | 41 | //22bit data reaD.intput()g |
esmiwa | 0:b28daf92293e | 42 | void XY_DATA () |
esmiwa | 0:b28daf92293e | 43 | { |
esmiwa | 0:b28daf92293e | 44 | x=0; |
esmiwa | 0:b28daf92293e | 45 | D.input(); |
esmiwa | 0:b28daf92293e | 46 | for(i=0;i<11;i++){ |
esmiwa | 0:b28daf92293e | 47 | CLK(High);CLK(Low); //clock down edge |
esmiwa | 0:b28daf92293e | 48 | x=x<<1; |
esmiwa | 0:b28daf92293e | 49 | x=x | D; //X data reaD.intput()g |
esmiwa | 0:b28daf92293e | 50 | } |
esmiwa | 0:b28daf92293e | 51 | y=0; |
esmiwa | 0:b28daf92293e | 52 | for(i=0;i<11;i++){ |
esmiwa | 0:b28daf92293e | 53 | CLK(High);CLK(Low); //clock down edge |
esmiwa | 0:b28daf92293e | 54 | y=y<<1; |
esmiwa | 0:b28daf92293e | 55 | y=y | D; //Y data reaD.intput()g |
esmiwa | 0:b28daf92293e | 56 | } |
esmiwa | 0:b28daf92293e | 57 | } |
esmiwa | 0:b28daf92293e | 58 | // reset sign out |
esmiwa | 0:b28daf92293e | 59 | void RESET(void) |
esmiwa | 0:b28daf92293e | 60 | { |
esmiwa | 0:b28daf92293e | 61 | D.output(); |
esmiwa | 0:b28daf92293e | 62 | CLK(High);D=0;CLK(Low); |
esmiwa | 0:b28daf92293e | 63 | CLK(High);D=0;CLK(Low); |
esmiwa | 0:b28daf92293e | 64 | CLK(High);D=0;CLK(Low); |
esmiwa | 0:b28daf92293e | 65 | CLK(High);D=0;CLK(Low); |
esmiwa | 0:b28daf92293e | 66 | } |
esmiwa | 0:b28daf92293e | 67 | //start sign out |
esmiwa | 0:b28daf92293e | 68 | void START(void) |
esmiwa | 0:b28daf92293e | 69 | { |
esmiwa | 0:b28daf92293e | 70 | D.output(); |
esmiwa | 0:b28daf92293e | 71 | CLK(High);D=1;CLK(Low); |
esmiwa | 0:b28daf92293e | 72 | CLK(High);D=0;CLK(Low); |
esmiwa | 0:b28daf92293e | 73 | CLK(High);D=0;CLK(Low); |
esmiwa | 0:b28daf92293e | 74 | CLK(High);D=0;CLK(Low); |
esmiwa | 0:b28daf92293e | 75 | } |
esmiwa | 0:b28daf92293e | 76 | |
esmiwa | 0:b28daf92293e | 77 | int READ_END_FLAG(void) |
esmiwa | 0:b28daf92293e | 78 | { |
esmiwa | 0:b28daf92293e | 79 | //int d[4]; |
esmiwa | 0:b28daf92293e | 80 | flag=0; |
esmiwa | 0:b28daf92293e | 81 | D.output(); |
esmiwa | 0:b28daf92293e | 82 | CLK(High);D=1;CLK(Low); |
esmiwa | 0:b28daf92293e | 83 | CLK(High);D=1;CLK(Low); |
esmiwa | 0:b28daf92293e | 84 | CLK(High);D=0;CLK(Low); |
esmiwa | 0:b28daf92293e | 85 | CLK(High);D=0;CLK(Low); |
esmiwa | 0:b28daf92293e | 86 | D.input(); |
esmiwa | 0:b28daf92293e | 87 | for(i=0;i<4;i++){ |
esmiwa | 0:b28daf92293e | 88 | CLK(High); |
esmiwa | 0:b28daf92293e | 89 | CLK(Low); //clock down edge |
esmiwa | 0:b28daf92293e | 90 | //d[i]=D; //1100 flag reaD |
esmiwa | 0:b28daf92293e | 91 | flag=flag<<1; |
esmiwa | 0:b28daf92293e | 92 | flag=flag+D; |
esmiwa | 0:b28daf92293e | 93 | myled4=D ; |
esmiwa | 0:b28daf92293e | 94 | } |
esmiwa | 0:b28daf92293e | 95 | //flag=d[0]*1000+d[1]*100+d[2]*10+d[3]; |
esmiwa | 0:b28daf92293e | 96 | return flag; |
esmiwa | 0:b28daf92293e | 97 | } |
esmiwa | 0:b28daf92293e | 98 | |
esmiwa | 0:b28daf92293e | 99 | int main() { |
esmiwa | 0:b28daf92293e | 100 | int cmd=0; |
esmiwa | 0:b28daf92293e | 101 | int dx=0;char *ax; |
esmiwa | 0:b28daf92293e | 102 | int dy=0;char *ay; |
esmiwa | 0:b28daf92293e | 103 | float atn; |
esmiwa | 0:b28daf92293e | 104 | |
esmiwa | 0:b28daf92293e | 105 | while(1){ |
esmiwa | 0:b28daf92293e | 106 | //lcd.cls(); |
esmiwa | 0:b28daf92293e | 107 | Csb=1; |
esmiwa | 0:b28daf92293e | 108 | //wait_ms(1); |
esmiwa | 0:b28daf92293e | 109 | Csb=0; |
esmiwa | 0:b28daf92293e | 110 | RESET(); |
esmiwa | 0:b28daf92293e | 111 | Csb=1; |
esmiwa | 0:b28daf92293e | 112 | //wait_ms(1); |
esmiwa | 0:b28daf92293e | 113 | Csb=0; |
esmiwa | 0:b28daf92293e | 114 | START(); |
esmiwa | 0:b28daf92293e | 115 | Csb=1; |
esmiwa | 0:b28daf92293e | 116 | wait_ms(30); //scanning |
esmiwa | 0:b28daf92293e | 117 | Csb=0; |
esmiwa | 0:b28daf92293e | 118 | cmd=READ_END_FLAG(); |
esmiwa | 0:b28daf92293e | 119 | XY_DATA(); |
esmiwa | 0:b28daf92293e | 120 | |
esmiwa | 0:b28daf92293e | 121 | if(x>1024){ dx=x-2048;ax="-S";} |
esmiwa | 0:b28daf92293e | 122 | else{ dx=x;ax="+N";} |
esmiwa | 0:b28daf92293e | 123 | if(y>1024){ dy=y-2048;ay="-E";} |
esmiwa | 0:b28daf92293e | 124 | else{ dy=y;ay="+W";} |
esmiwa | 0:b28daf92293e | 125 | atn=(float)dy/(float)dx; |
esmiwa | 0:b28daf92293e | 126 | Csb=1; |
esmiwa | 0:b28daf92293e | 127 | lcd.locate(0,0);lcd.printf(" X Y ATN"); |
esmiwa | 0:b28daf92293e | 128 | lcd.locate(0,1);lcd.printf(" %2s %2s %4.2f",ax,ay,atn); |
esmiwa | 0:b28daf92293e | 129 | wait_ms(40); //LCD dispaying |
esmiwa | 0:b28daf92293e | 130 | } |
esmiwa | 0:b28daf92293e | 131 | } |