น่าจะเสร็จแล้วนะฮะ

Dependencies:   eeprom mbed

Committer:
kong4580
Date:
Tue Nov 13 11:45:38 2018 +0000
Revision:
15:c0356b061d5e
Parent:
14:085075499b41
glgllg

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bi18rdbi18rd 5:eb65bd646089 1
soulx 0:8b5e53600ba0 2 #include "mbed.h"
soulx 0:8b5e53600ba0 3 #include "eeprom.h"
kong4580 14:085075499b41 4 Serial pc(USBTX,USBRX);
kong4580 15:c0356b061d5e 5 EEPROM memory(PB_9,PB_8,1);// A2=0 A1=0 A0=1
kong4580 14:085075499b41 6 BusIn dat(PB_4,PB_5,PB_3,PA_0,PA_1,PA_4,PB_0);
kong4580 14:085075499b41 7 BusOut led(PA_5,PA_6,PA_7,PB_6,PC_7,PA_9,PA_8);
kong4580 15:c0356b061d5e 8 DigitalIn m(PC_1); //toggle switch to select mode
kong4580 15:c0356b061d5e 9 InterruptIn button(D2); //deboounce button
kong4580 14:085075499b41 10 int mode = 0;
kong4580 14:085075499b41 11 int tic=0;
kong4580 14:085075499b41 12 void readmode(){
kong4580 15:c0356b061d5e 13 if (m == 0){ // if m = Low
kong4580 14:085075499b41 14 mode=0;
kong4580 14:085075499b41 15 tic=1;
kong4580 14:085075499b41 16
kong4580 15:c0356b061d5e 17 }else{ // if m = High
kong4580 14:085075499b41 18 mode=1;
kong4580 14:085075499b41 19 tic=1;}
kong4580 14:085075499b41 20 }
soulx 0:8b5e53600ba0 21 int main()
kong4580 14:085075499b41 22 {
kong4580 14:085075499b41 23 int8_t ac;
kong4580 15:c0356b061d5e 24 int16_t rcount=3;
kong4580 15:c0356b061d5e 25 int16_t count=3;
kong4580 14:085075499b41 26 button.fall(&readmode);
kong4580 15:c0356b061d5e 27 for (int i =0;i<1000;i++){
kong4580 14:085075499b41 28 memory.write(i,0);
kong4580 14:085075499b41 29 }
kong4580 14:085075499b41 30 while(1){
kong4580 14:085075499b41 31 int8_t dac= dat.read();
kong4580 14:085075499b41 32 if (mode==0 & tic==1){
kong4580 14:085075499b41 33 memory.write(count,dac);
kong4580 14:085075499b41 34 wait_ms(1);
kong4580 15:c0356b061d5e 35
kong4580 15:c0356b061d5e 36
kong4580 15:c0356b061d5e 37 pc.printf("Data in address %d = %d\n",count,dac);
kong4580 14:085075499b41 38 count+=1;
kong4580 14:085075499b41 39 tic=0;
kong4580 15:c0356b061d5e 40 rcount=3;
kong4580 14:085075499b41 41 }else if(mode ==1 & tic==1){
kong4580 14:085075499b41 42 memory.read(rcount,ac);
kong4580 14:085075499b41 43 led=ac;
kong4580 14:085075499b41 44 wait_ms(1);
kong4580 15:c0356b061d5e 45
kong4580 15:c0356b061d5e 46 pc.printf("Read in address %d = %d\n",rcount,ac);
kong4580 15:c0356b061d5e 47 rcount+=1;
kong4580 14:085075499b41 48 tic=0;
kong4580 15:c0356b061d5e 49 count=3;
kong4580 14:085075499b41 50 }
kong4580 14:085075499b41 51
kong4580 14:085075499b41 52 }
bi18rdbi18rd 5:eb65bd646089 53
soulx 0:8b5e53600ba0 54 }