热度 25
2012-10-31 23:45
2878 次阅读|
0 个评论
好了,杂乱的代码,还是放在一起好看: // used variables int back_posi_pin = 7; int back_nega_pin = 6; int vcc_pin = 13; int not_serial_pin = A1; int light_control_pin = A0; // the data pins int data_pin_2 = 2; int data_pin_3 = 8; int data_pin_1 = 3; int data_pin_0 = 12; int data_pin_4 = 11; int data_pin_5 = 10; int data_pin_6 = 9; int data_pin_7 = 5; int reset_pin = 4; int lightness = 200; // these are the control pins int rw_pin = A2; int e_pin = A3; int rs_pin = A4; // this array set the data situation int data_array = {0,0,1,1,0,0,0,0}; // the initial arrays int funcset = {0,0,0,0,1,1,0,0}; int display_clear = {1,1,1,0,0,0,0,0}; // not sure // the usual used commands int extend_func_on = {0,0,0,0,1,1,0,0}; int paint_on = {0,0,1,0,1,1,0,0}; int open_show = {0,1,1,0,0,0,0,0}; int temp = {bitRead(b,0),bitRead(b,1),bitRead(b,2),bitRead(b,3), bitRead(b,4),bitRead(b,5),bitRead(b,6),bitRead(b,7)}; write_data(adapt); } void write_cmd_adapt(unsigned char b){ int adapt ) { //delay(2); delayMicroseconds(500); set_e(); set_rs(); clear_rw(); set_data(b); set_e(); clear_e(); } unsigned char read_data() { unsigned char Rdata; pinMode(data_pin_0,INPUT); pinMode(data_pin_1,INPUT); pinMode(data_pin_2,INPUT); pinMode(data_pin_3,INPUT); pinMode(data_pin_4,INPUT); pinMode(data_pin_5,INPUT); pinMode(data_pin_6,INPUT); pinMode(data_pin_7,INPUT); set_rs(); set_rw(); clear_e(); set_e(); delayMicroseconds(500); Rdata = digitalRead(data_pin_0)+digitalRead(data_pin_0)*2+digitalRead(data_pin_0)*4 +digitalRead(data_pin_0)*8+digitalRead(data_pin_0)*16+digitalRead(data_pin_0)*32 +digitalRead(data_pin_0)*64+digitalRead(data_pin_0)*128; clear_e(); return Rdata; } void write_cmd(int a = a; temp = b; temp = c; temp = d; temp = e; temp = f; temp = g; temp = h; } void set_data(int data_array ==1){ digitalWrite(data_pin_0,HIGH); } else{ digitalWrite(data_pin_0,LOW); } if(data_array ==1){ digitalWrite(data_pin_1,HIGH); } else{ digitalWrite(data_pin_1,LOW); } if(data_array ==1){ digitalWrite(data_pin_2,HIGH); } else{ digitalWrite(data_pin_2,LOW); } if(data_array ==1){ digitalWrite(data_pin_3,HIGH); } else{ digitalWrite(data_pin_3,LOW); } if(data_array ==1){ digitalWrite(data_pin_4,HIGH); } else{ digitalWrite(data_pin_4,LOW); } if(data_array ==1){ digitalWrite(data_pin_5,HIGH); } else{ digitalWrite(data_pin_5,LOW); } if(data_array ==1){ digitalWrite(data_pin_6,HIGH); } else{ digitalWrite(data_pin_6,LOW); } if(data_array ==1){ digitalWrite(data_pin_7,HIGH); } else{ digitalWrite(data_pin_7,LOW); } } // functions to control the control signals void set_rw() { analogWrite(rw_pin,255); } void clear_rw() { analogWrite(rw_pin,0); } void set_rs() { analogWrite(rs_pin,255); } void clear_rs() { analogWrite(rs_pin,0); } void set_e() { analogWrite(e_pin,255); } void clear_e() { analogWrite(e_pin,0); } 好了,并行的方式就写到这里了,还是有很多的话的,耽误大家这么多时间,真是愧疚不已的。 下面就是串口的方式的介绍了,这回需要说的应该没那么多了。