//进入触摸屏校准函数 void Load_Adjust_Panel() { LCD_Clear(WHITE);//清屏 Touch_Adjust(); //屏幕校准 Save_Adjdata(); Load_Drow_Dialog(); }
int main(void) { u8 key; u8 i=0; SystemInit(); delay_init(72); //延时初始化 NVIC_Configuration(); uart_init(9600); LED_Init(); KEY_Init(); LCD_Init(); POINT_COLOR=RED;//设置字体为蓝色 LCD_ShowString(60,50,"Mini STM32"); LCD_ShowString(60,70,"TOUCH TEST"); LCD_ShowString(60,90,"ATOM@ALIENTEK"); LCD_ShowString(60,110,"2011/1/1"); LCD_ShowString(60,130,"Press KEY0 to Adjust"); Touch_Init(); delay_ms(1500); Load_Drow_Dialog(); while(1) { key=KEY_Scan(); if(Pen_Point.Key_Sta==Key_Down)//触摸屏被按下 { Pen_Int_Set(0);//关闭中断 do { Convert_Pos(); Pen_Point.Key_Sta=Key_Up; if(Pen_Point.X0>216&&Pen_Point.Y0<16)Load_Drow_Dialog();//清除 else { Draw_Big_Point(Pen_Point.X0,Pen_Point.Y0);//画图 GPIOC->ODR|=1<<1; //PC1 上拉 } }while(PEN==0);//如果PEN一直有效,则一直执行 Pen_Int_Set(1);//开启中断 }else delay_ms(10); if(key==1)//KEY0按下,则执行校准程序 { LCD_Clear(WHITE);//清屏 Touch_Adjust(); //屏幕校准 Save_Adjdata(); Load_Drow_Dialog(); } i++; if(i==20) { i=0; LED0=!LED0; } }; }
//外部中断初始化函数 void Touch_Init(void) { NVIC_InitTypeDef NVIC_InitStructure; //中断 GPIO_InitTypeDef GPIO_InitStructure; //GPIO EXTI_InitTypeDef EXTI_InitStructure; //外部中断线 //注意,时钟使能之后,对GPIO的操作才有效 //所以上拉之前,必须使能时钟.才能实现真正的上拉输出 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC | RCC_APB2Periph_AFIO, ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3|GPIO_Pin_0|GPIO_Pin_13; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //推挽输出 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOC, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1|GPIO_Pin_2; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU ; //上拉输入 GPIO_Init(GPIOC, &GPIO_InitStructure); Read_ADS(&Pen_Point.X,&Pen_Point.Y);//第一次读取初始化 NVIC_InitStructure.NVIC_IRQChannel = EXTI1_IRQn; //使能按键所在的外部中断通道 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2; //先占优先级2级 NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; //从优先级0级 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //使能外部中断通道 NVIC_Init(&NVIC_InitStructure); //根据NVIC_InitStruct中指定的参数初始化外设NVIC寄存器 RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE); GPIO_EXTILineConfig(GPIO_PortSourceGPIOC, GPIO_PinSource1); EXTI_InitStructure.EXTI_Line = EXTI_Line1; //外部线路EXIT1 EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; //设外外部中断模式:EXTI线路为中断请求 EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; //外部中断触发沿选择:设置输入线路下降沿为中断请求 EXTI_InitStructure.EXTI_LineCmd = ENABLE; //使能外部中断新状态 EXTI_Init(&EXTI_InitStructure); //根据EXTI_InitStruct中指定的参数初始化外设EXTI寄存器 #ifdef ADJ_SAVE_ENABLE AT24CXX_Init();//初始化24CXX if(Get_Adjdata())return;//已经校准 else //未校准? { LCD_Clear(WHITE);//清屏 Touch_Adjust(); //屏幕校准 Save_Adjdata(); } Get_Adjdata(); #else LCD_Clear(WHITE);//清屏 Touch_Adjust(); //屏幕校准,带自动保存 #endif }
//外部中断初始化函数 void Touch_Init(void) { //注意,时钟使能之后,对GPIO的操作才有效 //所以上拉之前,必须使能时钟.才能实现真正的上拉输出 RCC->APB2ENR|=1<<4; //PC时钟使能 RCC->APB2ENR|=1<<0; //开启辅助时钟 GPIOC->CRL&=0XFFFF0000;//PC0~3 GPIOC->CRL|=0X00003883; GPIOC->CRH&=0XFF0FFFFF;//PC13 GPIOC->CRH|=0X00300000;//PC13推挽输出 GPIOC->ODR|=0X200f; //PC0~3 13 全部上拉 Read_ADS(&Pen_Point.X,&Pen_Point.Y);//第一次读取初始化 MY_NVIC_Init(2,0,EXTI1_IRQChannel,2); RCC->APB2ENR|=0x01; //使能io复用时钟 AFIO->EXTICR[0]|=0X0020; //EXTI13映射到PC1 EXTI->IMR|=1<<1; //开启line1上的中断 EXTI->EMR|=1<<1; //不屏蔽line1上的事件 EXTI->FTSR|=1<<1; //line1上事件下降沿触发 #ifdef ADJ_SAVE_ENABLE AT24CXX_Init();//初始化24CXX if(Get_Adjdata())return;//已经校准 else //未校准? { LCD_Clear(WHITE);//清屏 Touch_Adjust(); //屏幕校准 Save_Adjdata(); } Get_Adjdata(); #else LCD_Clear(WHITE);//清屏 Touch_Adjust(); //屏幕校准,带自动保存 #endif // printf("Pen_Point.xfac:%f\n",Pen_Point.xfac); // printf("Pen_Point.yfac:%f\n",Pen_Point.yfac); // printf("Pen_Point.xoff:%d\n",Pen_Point.xoff); // printf("Pen_Point.yoff:%d\n",Pen_Point.yoff); }
int main(void) { /////////////////////////////////////////// uint8_t Key; int i; //////////////////////////////////////////////// brightness = 0x40;//亮度 contrast = 0x70;//对比度 saturation = 0x40;//饱和度 memset(outbuf,0,64); SystemInit(); //GPIOInit(); //chumo改版加入 //Touch_Initializtion(); Init_NVIC(); //中断向量表注册函数 Init_LED(); //LED初始化 Init_KEY(); //按键初始化 Init_IIC(); //24LC02初始化 Init_TOUCH(); // 触摸屏配置 //Touch_Initializtion(); ////////// UART3_Init(115200); PrintStr("=========12345========\r\n"); //ADC_Init_Ex(); //Tim3_ETR_Init(); //Tim4_Init(); //CAN1_Init(250); // USB_Init(); // RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE); /* Configure FSMC Bank1 NOR/SRAM3 */ //FSMC_SRAM_Init(); DelayMs(300); //InitSSD1963(); //LcdInitTest(); LcdInit(); LcdClear(GRAY0); DispButton(button2); DisplayButtonUp(2, 2,400,25); LcdPrintStr("版权所有(C)mmmmmmmmmmmmmmmmmmmm",4,4,BLUE,GRAY0); DisplayButtonUp(402,2,478,25); LcdPrintf(410,4,BLACK,GRAY0,"%02d:%02d:%02d",12,12,12); DisplayButtonDownColor(200, 410, 290, 470, RED); DisplayButtonDownColor(412, 410, 502, 470, GREEN); LcdPrintStr("删除",230,432,WHITE,RED); LcdPrintStr("确认",442,432,BLACK,GREEN); LcdFillRec(200,100,502,190,DGREEN); DisplayButtonUp(190,90,512,475); DelayMs(1000); LcdFillRec(190,90,512,475,RED); DelayMs(1000); LcdFillRec(190,90,512,475,GRAY0); DispButton(button2); DisplayButtonDownColor(200, 410, 290, 470, RED); DisplayButtonDownColor(412, 410, 502, 470, GREEN); LcdPrintStr("删除",230,432,WHITE,RED); LcdPrintStr("确认",442,432,BLACK,GREEN); LcdFillRec(200,100,502,190,DGREEN); DisplayButtonUp(190,90,512,475); // Pen_Point.Key_Sta==Key_Up; //LcdPrint16bitBmp(gImage, 16, 16, 490, 368 ); while(1) { // if(Pen_Point.Key_Sta==Key_Down) // { // LcdPrintf( 16,16,BLUE,WHITE,"%d",ADS_Read_AD(CMD_RDX)); // LcdPrintf( 16,32,BLUE,WHITE,"%d",ADS_Read_AD(CMD_RDY)); // } //LcdPrintf( 16,32,BLUE,WHITE,"%d",Touch_GetPhyY()); //LcdPrintf( 16,16,BLUE,WHITE,"%d",Touch_GetPhyX()); // DelayMs(200); // LED1 = ~LED1; //LED1=~LED1; //DelayMs(50); //////////////////////////////////////// Key=KEY_Scan(); if(Pen_Point.Key_Sta==Key_Down)//触摸屏被按下 { Pen_Int_Set(0); //关闭中断 do { LcdPrintf( 16,16,BLUE,WHITE,"%d",ADS_Read_AD(CMD_RDX)); LcdPrintf( 16,32,BLUE,WHITE,"%d",ADS_Read_AD(CMD_RDY)); Convert_Pos(); Pen_Point.Key_Sta=Key_Up; //GPIOC->ODR|=1<<5;//临时添加 // LcdPrintf(16,16,BLUE,BLACK,"%d\n",Pen_Point.X); // LcdPrintf(16,32,BLUE,BLACK,"%d\n",Pen_Point.Y); if(Pen_Point.X0>216&&Pen_Point.Y0<48)LcdClear(RED);//清除 else { Draw_Big_Point(Pen_Point.X0,Pen_Point.Y0);//画图 GPIOC->ODR|=1<<5; //PC5 上拉 } }while(PEN==0);//如果PEN一直有效,则一直执行 Pen_Int_Set(1);//开启中断 } else DelayMs(1); if(Key==USER)//USER按下,则执行校准程序 { LcdClear(BlackColor);//清屏 Touch_Adjust(); //屏幕校准 Save_Adjdata(); LcdClear(RED); } i++; if(i==1) { i=0; LED1=~LED1; } } /////////////////////////////////// /* if(_SEC_) { _SEC_ = 0; GPIO_WriteBit(GPIOC, GPIO_Pin_6, (BitAction)(1 - GPIO_ReadOutputDataBit(GPIOC, GPIO_Pin_6))); LcdPrintf(300,460,BLACK,GRAY0,"%03d",i); //i += 10; SetSensors(); for(u8 i=1; i<=16; i++) Printf("No.%d=%d,",i,GetSensorVoltage(i)); PrintStr("\r\n"); } UART1_SendByte(0x55); DelayMs(1); } */ }