自己設(shè)計的,模擬dtmf電話撥碼系統(tǒng),開發(fā)板用的是stm32,功能是通過按鍵輸出到stm32,并通過TFTLCD顯示。剛開始用的矩陣鍵盤,但由于開發(fā)板io口有限,自己做了一個觸摸屏,并在觸摸屏上顯示數(shù)字,通過tlc5615輸出兩路疊加的模擬信號。本工程為大致工程,有問題請回帖
單片機源程序如下:
- #include "sys.h"
- #include "usart.h"
- #include "delay.h"
- #include "led.h"
- #include "lcd.h"
- #include "key.h"
- #include "24cxx.h"
- #include "touch.h"
- #include <stdlib.h>
- #include "delay.h"
- #include "tlc5615.h"
- #include "wave_form.h"
- //#include "stm32f10x_rcc.h"
- //#include "stm32f10x_spi.h"
- //#include "stm32f10x_gpio.h"
-
- void Draw_Board(void);
- void Scan_Board(void);
- //void TCL5615_init(void);
- //void sin_wave(void);
- void Load_Drow_Dialog(void)
- {
- LCD_Clear(WHITE);//清屏
- POINT_COLOR=BLUE;//設(shè)置字體為藍色
- LCD_ShowString(lcddev.width-24,0,200,16,16,"RST");//顯示清屏區(qū)域
- POINT_COLOR=RED;//設(shè)置畫筆藍色
- }
- ////////////////////////////////////////////////////////////////////////////////
- //電容觸摸屏專有部分
- //畫水平線
- //x0,y0:坐標(biāo)
- //len:線長度
- //color:顏色
- void gui_draw_hline(u16 x0,u16 y0,u16 len,u16 color)
- {
- if(len==0)return;
- LCD_Fill(x0,y0,x0+len-1,y0,color);
- }
- //畫實心圓
- //x0,y0:坐標(biāo)
- //r:半徑
- //color:顏色
- void gui_fill_circle(u16 x0,u16 y0,u16 r,u16 color)
- {
- u32 i;
- u32 imax = ((u32)r*707)/1000+1;
- u32 sqmax = (u32)r*(u32)r+(u32)r/2;
- u32 x=r;
- gui_draw_hline(x0-r,y0,2*r,color);
- for (i=1;i<=imax;i++)
- {
- if ((i*i+x*x)>sqmax)// draw lines from outside
- {
- if (x>imax)
- {
- gui_draw_hline (x0-i+1,y0+x,2*(i-1),color);
- gui_draw_hline (x0-i+1,y0-x,2*(i-1),color);
- }
- x--;
- }
- // draw lines from inside (center)
- gui_draw_hline(x0-x,y0+i,2*x,color);
- gui_draw_hline(x0-x,y0-i,2*x,color);
- }
- }
- //兩個數(shù)之差的絕對值
- //x1,x2:需取差值的兩個數(shù)
- //返回值:|x1-x2|
- u16 my_abs(u16 x1,u16 x2)
- {
- if(x1>x2)return x1-x2;
- else return x2-x1;
- }
- //畫一條粗線
- //(x1,y1),(x2,y2):線條的起始坐標(biāo)
- //size:線條的粗細程度
- //color:線條的顏色
- void lcd_draw_bline(u16 x1, u16 y1, u16 x2, u16 y2,u8 size,u16 color)
- {
- u16 t;
- int xerr=0,yerr=0,delta_x,delta_y,distance;
- int incx,incy,uRow,uCol;
- if(x1<size|| x2<size||y1<size|| y2<size)return;
- delta_x=x2-x1; //計算坐標(biāo)增量
- delta_y=y2-y1;
- uRow=x1;
- uCol=y1;
- if(delta_x>0)incx=1; //設(shè)置單步方向
- else if(delta_x==0)incx=0;//垂直線
- else {incx=-1;delta_x=-delta_x;}
- if(delta_y>0)incy=1;
- else if(delta_y==0)incy=0;//水平線
- else{incy=-1;delta_y=-delta_y;}
- if( delta_x>delta_y)distance=delta_x; //選取基本增量坐標(biāo)軸
- else distance=delta_y;
- for(t=0;t<=distance+1;t++ )//畫線輸出
- {
- gui_fill_circle(uRow,uCol,size,color);//畫點
- xerr+=delta_x ;
- yerr+=delta_y ;
- if(xerr>distance)
- {
- xerr-=distance;
- uRow+=incx;
- }
- if(yerr>distance)
- {
- yerr-=distance;
- uCol+=incy;
- }
- }
- }
- ////////////////////////////////////////////////////////////////////////////////
- //5個觸控點的顏色
- //電阻觸摸屏測試函數(shù)
- void rtp_test(void)
- {
- u8 key;
- u8 i=0;
- while(1)
- {
- key=KEY_Scan(0);
- Scan_Board();
- // tp_dev.scan(0);
- // if(tp_dev.sta&TP_PRES_DOWN) //觸摸屏被按下
- // {
- // if(tp_dev.x[0]<lcddev.width&&tp_dev.y[0]<lcddev.height)
- // {
- // if(tp_dev.x[0]>(lcddev.width-24)&&tp_dev.y[0]<16)
- // {
- // Load_Drow_Dialog();//清除
- // LCD_ShowString(30,40,200,24,24,"1");
- // }
- //// else TP_Draw_Big_Point(tp_dev.x[0],tp_dev.y[0],RED); //畫圖
- // }
- // }else delay_ms(10); //沒有按鍵按下的時候
- if(key==KEY0_PRES) //KEY0按下,則執(zhí)行校準(zhǔn)程序
- {
- LCD_Clear(WHITE);//清屏
- TP_Adjust(); //屏幕校準(zhǔn)
- TP_Save_Adjdata();
- Load_Drow_Dialog();
- }
- i++;
- if(i%20==0)LED0=!LED0;
- }
- }
- const u16 POINT_COLOR_TBL[CT_MAX_TOUCH]={RED,GREEN,BLUE,BROWN,GRED};
- //電容觸摸屏測試函數(shù)
- void ctp_test(void)
- {
- u8 t=0;
- u8 i=0;
- u16 lastpos[5][2]; //最后一次的數(shù)據(jù)
- while(1)
- {
- tp_dev.scan(0);
- for(t=0;t<CT_MAX_TOUCH;t++)//最多5點觸摸
- {
- if((tp_dev.sta)&(1<<t))//判斷是否有點觸摸?
- {
- if(tp_dev.x[t]<lcddev.width&&tp_dev.y[t]<lcddev.height)//在LCD范圍內(nèi)
- {
- if(lastpos[t][0]==0XFFFF)
- {
- lastpos[t][0] = tp_dev.x[t];
- lastpos[t][1] = tp_dev.y[t];
- }
- lcd_draw_bline(lastpos[t][0],lastpos[t][1],tp_dev.x[t],tp_dev.y[t],2,POINT_COLOR_TBL[t]);//畫線
- lastpos[t][0]=tp_dev.x[t];
- lastpos[t][1]=tp_dev.y[t];
- if(tp_dev.x[t]>(lcddev.width-24)&&tp_dev.y[t]<16)
- {
- Load_Drow_Dialog();//清除
- }
- }
- }else lastpos[t][0]=0XFFFF;
- }
-
- delay_ms(5);i++;
- if(i%20==0)LED0=!LED0;
- }
- }
- void Draw_Check(void)
- {
- LCD_DrawLine(10,195+10,240-10,195+10);//00
- LCD_DrawLine(10,230+10,240-10,230+10);
- LCD_DrawLine(10,265+10,240-10,265+10);
- LCD_DrawLine(10+55,160+10,10+55,320-10);
- LCD_DrawLine(10+55,160+10,10+55,320-10);
- LCD_DrawLine(10+110,160+10,10+110,320-10);
- LCD_DrawLine(10+165,160+10,10+165,320-10);
- }
- void LCD_ShowNumber(void)
- {
- LCD_ShowString(25,175,25,25,24,"1");
- LCD_ShowString(75,175,25,25,24,"2");
- LCD_ShowString(125,175,25,25,24,"3");
- LCD_ShowString(180,175,25,25,24,"A");
- LCD_ShowString(25,210,25,25,24,"4");
- LCD_ShowString(75,210,25,25,24,"5");
- LCD_ShowString(125,210,25,25,24,"6");
- LCD_ShowString(180,210,25,25,24,"B");
- LCD_ShowString(25,245,25,25,24,"7");
- LCD_ShowString(75,245,25,25,24,"8");
- LCD_ShowString(125,245,25,25,24,"9");
- LCD_ShowString(180,245,25,25,24,"C");
- LCD_ShowString(25,280,25,25,24,"*");
- LCD_ShowString(75,280,25,25,24,"0");
- LCD_ShowString(125,280,25,25,24,"#");
- LCD_ShowString(180,280,25,25,24,"D");
- }
- void Draw_Board(void)
- {
- LCD_DrawRectangle(10,160+10,240-10,320-10);
- }
- //void Scan_Board(void)
- //{
- //// u8 show_string[8];00
- ////show_string = (u8 *) malloc(1);00
- // tp_dev.scan(0);
- // if(tp_dev.sta&TP_PRES_DOWN) //觸摸屏被按下
- // {
- //// printf("x:%3d, y:%3d\r\n",tp_dev.x[0], tp_dev.y[0]);00
- // if(tp_dev.x[0]<(240-5)&&tp_dev.y[0]<(320-5))
- // {
- // if(tp_dev.x[0]>(5)&&tp_dev.y[0]>(160+5));
- // {
- // LCD_ShowString(30,40,200,24,24,"X:");
- // LCD_ShowxNum(60,40,(u32)tp_dev.x[0],3,24,0x00);
- // LCD_ShowString(30,70,200,24,24,"Y:");
- // LCD_ShowxNum(60,70,(u32)tp_dev.y[0],3,24,0x00);
- // }
- // }
- // }else delay_ms(10); //沒有按鍵按下的時候
- //// free(show_string); 00
- //}
- void Scan_Board(void)
- {
- tp_dev.scan(0);
- if(tp_dev.sta&TP_PRES_DOWN) //觸摸屏被按下
- {
- if(tp_dev.x[0]<(65)&&tp_dev.y[0]<(205)&&tp_dev.x[0]>10&&tp_dev.y[0]>170)
- {
- LCD_ShowString(60,50,200,16,16,"The Number Is:");
- LCD_ShowString(60,70,200,16,16,"1");
- sin_wave();
- }
- if(tp_dev.x[0]<(120)&&tp_dev.y[0]<(205)&&tp_dev.x[0]>65&&tp_dev.y[0]>170)
- {
- LCD_ShowString(60,50,200,16,16,"The Number Is:");
- LCD_ShowString(60,70,200,16,16,"2");
- }
- if(tp_dev.x[0]<(175)&&tp_dev.y[0]<(205)&&tp_dev.x[0]>120&&tp_dev.y[0]>170)
- {
- LCD_ShowString(60,50,200,16,16,"The Number Is:");
- LCD_ShowString(60,70,200,16,16,"3");
- }
- if(tp_dev.x[0]<(230)&&tp_dev.y[0]<(205)&&tp_dev.x[0]>175&&tp_dev.y[0]>170)
- {
- LCD_ShowString(60,50,200,16,16,"The Number Is:");
- LCD_ShowString(60,70,200,16,16,"A");
- }
- if(tp_dev.x[0]<(65)&&tp_dev.y[0]<(240)&&tp_dev.x[0]>10&&tp_dev.y[0]>205)
- {
- LCD_ShowString(60,50,200,16,16,"The Number Is:");
- LCD_ShowString(60,70,200,16,16,"4");
- }
- if(tp_dev.x[0]<(120)&&tp_dev.y[0]<(240)&&tp_dev.x[0]>65&&tp_dev.y[0]>205)
- {
- LCD_ShowString(60,50,200,16,16,"The Number Is:");
- LCD_ShowString(60,70,200,16,16,"5");
- }
- if(tp_dev.x[0]<(175)&&tp_dev.y[0]<(240)&&tp_dev.x[0]>120&&tp_dev.y[0]>205)
- {
- LCD_ShowString(60,50,200,16,16,"The Number Is:");
- LCD_ShowString(60,70,200,16,16,"6");
- }
- if(tp_dev.x[0]<(230)&&tp_dev.y[0]<(240)&&tp_dev.x[0]>175&&tp_dev.y[0]>205)
- {
- LCD_ShowString(60,50,200,16,16,"The Number Is:");
- LCD_ShowString(60,70,200,16,16,"B");
- }
- if(tp_dev.x[0]<(65)&&tp_dev.y[0]<(275)&&tp_dev.x[0]>10&&tp_dev.y[0]>240)
- {
- LCD_ShowString(60,50,200,16,16,"The Number Is:");
- LCD_ShowString(60,70,200,16,16,"7");
- }
- if(tp_dev.x[0]<(120)&&tp_dev.y[0]<(275)&&tp_dev.x[0]>65&&tp_dev.y[0]>240)
- {
- LCD_ShowString(60,50,200,16,16,"The Number Is:");
- LCD_ShowString(60,70,200,16,16,"8");
- }
- if(tp_dev.x[0]<(175)&&tp_dev.y[0]<(275)&&tp_dev.x[0]>120&&tp_dev.y[0]>240)
- {
- LCD_ShowString(60,50,200,16,16,"The Number Is:");
- LCD_ShowString(60,70,200,16,16,"9");
- }
- if(tp_dev.x[0]<(230)&&tp_dev.y[0]<(275)&&tp_dev.x[0]>175&&tp_dev.y[0]>240)
- {
- LCD_ShowString(60,50,200,16,16,"The Number Is:");
- LCD_ShowString(60,70,200,16,16,"C");
- }
- if(tp_dev.x[0]<(65)&&tp_dev.y[0]<(310)&&tp_dev.x[0]>10&&tp_dev.y[0]>275)
- {
- LCD_ShowString(60,50,200,16,16,"The Number Is:");
- LCD_ShowString(60,70,200,16,16,"*");
- }
- if(tp_dev.x[0]<(120)&&tp_dev.y[0]<(310)&&tp_dev.x[0]>65&&tp_dev.y[0]>275)
- {
- LCD_ShowString(60,50,200,16,16,"The Number Is:");
- LCD_ShowString(60,70,200,16,16,"0");
- }
- if(tp_dev.x[0]<(175)&&tp_dev.y[0]<(310)&&tp_dev.x[0]>120&&tp_dev.y[0]>275)
- {
- LCD_ShowString(60,50,200,16,16,"The Number Is:");
- LCD_ShowString(60,70,200,16,16,"#");
- }
- if(tp_dev.x[0]<(230)&&tp_dev.y[0]<(310)&&tp_dev.x[0]>175&&tp_dev.y[0]>275)
- {
- LCD_ShowString(60,50,200,16,16,"The Number Is:");
- LCD_ShowString(60,70,200,16,16,"D");
- }
- }
- }
- int main(void)
- {
- Stm32_Clock_Init(9); //系統(tǒng)時鐘設(shè)置
- uart_init(72,9600); //串口初始化為9600
- delay_init(72); //延時初始化
- LED_Init(); //初始化與LED連接的硬件接口
- LCD_Init(); //初始化LCD
- KEY_Init(); //按鍵初始化
- TCL5615_init();
- tp_dev.init(); //觸摸屏初始化
- POINT_COLOR=RED;//設(shè)置字體為紅色
- // LCD_ShowString(60,50,200,16,16,"The Number Is:");
- // LCD_ShowString(60,70,200,16,16,"TOUCH TEST");
- // LCD_ShowString(60,90,200,16,16,"ATOM@ALIENTEK");
- // LCD_ShowString(60,110,200,16,16,"2014/3/11");
- //if(tp_dev.touchtype!=0XFF)LCD_ShowString(60,130,200,16,16,"Press KEY0 to Adjust");//電阻屏才顯示
- delay_ms(1500);
- Load_Drow_Dialog();//清屏
- LCD_ShowNumber();
- // LCD_ShowString(25,175,25,25,24,"1");
- // LCD_ShowString(75,175,25,25,24,"2");
- // LCD_ShowString(125,175,25,25,24,"3");
- // LCD_ShowString(180,175,25,25,24,"A");
- // LCD_ShowString(25,210,25,25,24,"4");
- // LCD_ShowString(75,210,25,25,24,"5");
- // LCD_ShowString(125,210,25,25,24,"6");
- // LCD_ShowString(180,210,25,25,24,"B");
- // LCD_ShowString(25,245,25,25,24,"7");
- // LCD_ShowString(75,245,25,25,24,"8");
- // LCD_ShowString(125,245,25,25,24,"9");
- // LCD_ShowString(180,245,25,25,24,"C");
- // LCD_ShowString(25,280,25,25,24,"*");
- // LCD_ShowString(75,280,25,25,24,"0");
- // LCD_ShowString(125,280,25,25,24,"#");
- // LCD_ShowString(180,280,25,25,24,"D");
- // LCD_DrawLine(10,195+10,240-10,195+10);//00
- // LCD_DrawLine(10,230+10,240-10,230+10);
- // LCD_DrawLine(10,265+10,240-10,265+10);
- // LCD_DrawLine(10+55,160+10,10+55,320-10);
- // LCD_DrawLine(10+55,160+10,10+55,320-10);
- // LCD_DrawLine(10+110,160+10,10+110,320-10);
- // LCD_DrawLine(10+165,160+10,10+165,320-10);
- Draw_Check();
- Draw_Board();
- if(tp_dev.touchtype&0X80)ctp_test(); //電容屏測試
- else rtp_test(); //電阻屏測試
- }
復(fù)制代碼
所有資料51hei提供下載:
觸摸屏按鍵.7z
(271.78 KB, 下載次數(shù): 20)
2019-6-29 17:40 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
|