?? main.c
字號:
LCD_1_Init();
LCD_1_PrCString("initial button sensitive");delay(20);
/*
for(i=0;i<4;i++){// adjust sensitive
write_memory(SLAVE_ADDRESS,write_negthreshold_addr,17);
write_memory(SLAVE_ADDRESS,write_negthreshold_addr,17);
}*/
delay(50);
read_memory(SLAVE_ADDRESS,read_negthreshold_addr,rxbuffer,16);
LCD_1_Init();
LCD_1_Position(0,0);
lcd_display(rxbuffer,16);
delay(50);
/*
delay(50);
for(i=0;i<4;i++){// adjust sensitive
write_memory(SLAVE_ADDRESS,write_burstlength_addr,17);
write_memory(SLAVE_ADDRESS,write_burstlength_addr,17);
}*/
LCD_1_Init();
delay(50);
read_memory(SLAVE_ADDRESS,read_burstlength_addr,rxbuffer,16);//for debug
LCD_1_Position(0,0);
lcd_display(rxbuffer,16);
delay(50);
M8C_EnableGInt;//enable globa interrupt bit
//M8C_EnableIntMask(INT_MSK0,INT_MSK0_GPIO);//enable gpio interrupt
/**************************************************************************
ADC OPERATION
***************************************************************************/
//Counter8_1_Start();
PGA_1_Start(PGA_1_HIGHPOWER); // turn on pga
PGA_1_SetPower(PGA_1_HIGHPOWER); //
//PGA_1_SetGain(BYTE bGainSetting); //
// PGA_1_Stop(void); //
ADCINC12_1_Start(PGA_1_HIGHPOWER);
ADCINC12_1_SetPower(ADCINC12_1_HIGHPOWER );
ADCINC12_1_GetSamples(0);
while(ADCINC12_1_fIsDataAvailable()==0);
adc_data=ADCINC12_1_iGetData();
ADCINC12_1_ClearFlag();
convert_ascii_data(adc_data);
for(k=0;k<6;k++){
LCD_1_Write_Data(lcd_data[k]);//the data write to LCD is ASCII code format
}
LCD_1_Init();
LCD_1_PrCString("checking power:");delay(50);
LCD_1_Position(0,16);// V3S VALUE
LCD_1_PrHexInt(adc_data);//display data
LCD_1_Position(1,14);
for(l=0;l<6;l++){
LCD_1_Write_Data(lcd_data[l]);//the data write to LCD is ASCII code format
}
ADCINC12_1_StopAD();
ADCINC12_1_Stop();
delay(100);
while(1){// main loop
//write_memory(SLAVE_ADDRESS,write_calibrate_addr,2); //calibrate all pad
PRT1DR=0;
k=0;
/*do{
PRT1DR=0x07;//turn on led
write_memory(SLAVE_ADDRESS,write_gpio_direction_addr,2);//config gpio1 as output
write_memory(SLAVE_ADDRESS,write_gpio_driveh_addr,2);//switch off num led
*/
do{
//Counter8_1_Start();
PGA_1_Start(PGA_1_HIGHPOWER); // turn on pga
PGA_1_SetPower(PGA_1_HIGHPOWER); //
//PGA_1_SetGain(BYTE bGainSetting); //
// PGA_1_Stop(void); //
ADCINC12_1_Start(PGA_1_HIGHPOWER);
ADCINC12_1_SetPower(ADCINC12_1_HIGHPOWER );
ADCINC12_1_GetSamples(0);
while(ADCINC12_1_fIsDataAvailable()==0);
adc_data=ADCINC12_1_iGetData();
ADCINC12_1_ClearFlag();
convert_ascii_data(adc_data);//convert to ASCII code
LCD_1_Init();
LCD_1_PrCString("checking power:");delay(50);
LCD_1_Position(0,16);// V3S VALUE
LCD_1_PrHexInt(adc_data);//display data
LCD_1_Position(1,14);
for(l=0;l<6;l++){
LCD_1_Write_Data(lcd_data[l]);//the data write to LCD is ASCII code format
}
ADCINC12_1_StopAD();
ADCINC12_1_Stop();
delay(100);
//delay(20);
PRT1DR=0x00;
//write_memory(SLAVE_ADDRESS,write_gpio_direction_addr,2);//config gpio1 as output
write_memory(SLAVE_ADDRESS,write_gpio_drivel_addr,2);//switch on num led
delay(20);
k++;
}while(k<3);
button_status.flag_x0y0=0;
button_status.flag_x1y0=0;
button_status.flag_x2y0=0;
button_status.flag_x3y0=0;
button_status.flag_x4y0=0;
button_status.flag_x0y1=0;
button_status.flag_x1y1=0;
button_status.flag_x2y1=0;
button_status.flag_x3y1=0;
button_status.flag_x4y1=0;
button_status.flag_x5y1=0;
button_status.flag_x6y1=0;
button_status.flag_x7y1=0;
write_memory(SLAVE_ADDRESS,write_calibrate_addr,2); //calibrate all pad
LCD_1_Init();
LCD_1_Position(1,2);
LCD_1_PrCString("slider button");
LCD_1_Position(2,2);
LCD_1_PrCString("12345 6789abcd");
PRT1DR=0x00;
write_memory(SLAVE_ADDRESS,write_gpio_direction_addr,2);//config gpio1 as output
write_memory(SLAVE_ADDRESS,write_gpio_driveh_addr,2);//switch on num led
write_memory(SLAVE_ADDRESS,write_gpio_direction_addr,2);//config gpio1 as output
write_memory(SLAVE_ADDRESS,write_gpio_driveh_addr,2);//switch on num led
write_memory(SLAVE_ADDRESS,write_gpio_direction_addr,2);//config gpio1 as output
write_memory(SLAVE_ADDRESS,write_gpio_driveh_addr,2);//switch on num led
/**************************************************************
initial swb
************************************************************/
//write_memory(SLAVE_ADDRESS,write_calibrate_addr,2); //calibrate all pad
do{ //read_memory(SLAVE_ADDRESS,read_keystatus1_addr,rxbuffer,2);// Read slider and PAD STATUS from swb
read_memory(SLAVE_ADDRESS,read_keystatus1_addr,rxbuffer,2);// Read slider and PAD STATUS from swb
LCD_1_Position(0,7);// for debug message
lcd_display(rxbuffer,2);//display data
switch(rxbuffer[0]){// (slider)***** (button)*********
case 0x01:LCD_1_Position(2,2);LCD_1_PrCString("*");button_status.flag_x0y0=1;break;
case 0x02:LCD_1_Position(2,3);LCD_1_PrCString("*");button_status.flag_x1y0=1;break;
case 0x03:LCD_1_Position(2,2);LCD_1_PrCString("**");button_status.flag_x0y0=1;
button_status.flag_x1y0=1;break;// ADD SENSITIVE
case 0x04:LCD_1_Position(2,4);LCD_1_PrCString("*"); button_status.flag_x2y0=1;break;
case 0x05:LCD_1_Position(2,2);LCD_1_PrCString("***");button_status.flag_x0y0=1;
button_status.flag_x1y0=1;
button_status.flag_x2y0=1;break;// ADD SENSITIVE
case 0x06:LCD_1_Position(2,2);LCD_1_PrCString("***");button_status.flag_x0y0=1;
button_status.flag_x1y0=1;
button_status.flag_x2y0=1;break;// ADD SENSITIVE
case 0x07:LCD_1_Position(2,2);LCD_1_PrCString("***");button_status.flag_x0y0=1;
button_status.flag_x1y0=1;
button_status.flag_x2y0=1;break;// ADD SENSITIVE
case 0x08:LCD_1_Position(2,5);LCD_1_PrCString("*");button_status.flag_x3y0=1;break;
case 0x09:LCD_1_Position(2,2);LCD_1_PrCString("****");button_status.flag_x0y0=1;
button_status.flag_x1y0=1;
button_status.flag_x2y0=1;
button_status.flag_x3y0=1;break;// ADD SENSITIVE
case 0x10:LCD_1_Position(2,6);LCD_1_PrCString("*");button_status.flag_x4y0=1;break;
default: break;
}
//read_memory(SLAVE_ADDRESS,read_keystatus1_addr,rxbuffer,2);// Read slider and PAD STATUS from swb
read_memory(SLAVE_ADDRESS,read_keystatus1_addr,rxbuffer,2);// Read slider and PAD STATUS from swb
switch(rxbuffer[1]){
case 0x01:LCD_1_Position(2,10);LCD_1_PrCString("*");button_status.flag_x0y1=1;break;
case 0x02:LCD_1_Position(2,11);LCD_1_PrCString("*");button_status.flag_x1y1=1;break;
case 0x04:LCD_1_Position(2,12);LCD_1_PrCString("*");button_status.flag_x2y1=1;PRT1DR=PRT1DR|0x01;break;
case 0x08:LCD_1_Position(2,13);LCD_1_PrCString("*");button_status.flag_x3y1=1;break;
case 0x10:LCD_1_Position(2,14);LCD_1_PrCString("*");button_status.flag_x4y1=1;break;
case 0x20:LCD_1_Position(2,15);LCD_1_PrCString("*");button_status.flag_x5y1=1;break;
case 0x40:LCD_1_Position(2,16);LCD_1_PrCString("*");button_status.flag_x6y1=1;break;
case 0x80:LCD_1_Position(2,17);LCD_1_PrCString("*");button_status.flag_x7y1=1;PRT1DR=PRT1DR|0x02;break;
default:break;
}
} while( (button_status.flag_x0y0==0)
||(button_status.flag_x1y0==0)
||(button_status.flag_x2y0==0)
||(button_status.flag_x3y0==0)
||(button_status.flag_x4y0==0)
||(button_status.flag_x0y1==0)
||(button_status.flag_x1y1==0)
||(button_status.flag_x2y1==0)
||(button_status.flag_x3y1==0)
||(button_status.flag_x4y1==0)
||(button_status.flag_x5y1==0)
||(button_status.flag_x6y1==0)
||(button_status.flag_x7y1==0)
);
//delay(10);
PRT1DR=0x00;
LCD_1_Position(3,6);
LCD_1_PrCString("TEST ok");
delay(100);
write_memory(SLAVE_ADDRESS,write_gpio_drivel_addr,2);//switch off num led
LCD_1_Position(3,6);
LCD_1_PrCString(" ");
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -