helloyesyes 发表于 2013-1-26 13:36:54

S3C2440-触摸屏

程序仍在调试中

#include "2440addr.h"#include "Font_Libs.h"//垂直同步信号的脉宽、后肩和前肩    #define VSPW       15    #define VBPD       3    #define VFPD       5   //水平同步信号的脉宽、后肩和前肩    #define HSPW       8    #define HBPD       58    #define HFPD      15    #define CLKVAL 10    #define HOZVAL 319    #define LINEVAL 239    #define PWREN 1    #define MMODE 0    #define PNRMODE 3    #define BPPMODE 13    #define INVVCLK 0    #define INVVD 0    #define INVVDEN 0   #define U32 unsigned int   #define M5D(n) ((n) & 0x1fffff)    #define PAGEWIDTH 320    #define OFFSIZE 0    #define LCD_XSIZE 320    #define LCD_YSIZE 240    #define SCR_XSIZE 320    #define SCR_YSIZE 240    #define INVVLINE1      #define INVVFRAME 1         #define BPP24BL 0    #define BSWP 0    #define HWSWP 0   #define U32 unsigned int#define U8 unsigned charunsigned char iic_buffer;   U32 length, A, B, C, D, E, F, K, FlagTc, xx , yy, i;U32 x, y;   unsigned char add, word;   int cmd, flag, count, command, fuck, fucker;   volatile U32 LCD_BUFFER;   volatile int xdata, ydata;void delay(int a)   {       int k;       for(k=0;k<a;k++)         ;   }void Paint_background(U32 c){         unsigned int i, j;         for(j = 0; j < LCD_YSIZE; j++)             for(i = 0; i < LCD_XSIZE; i++)               LCD_BUFFER = c;   }void DrawCircle(U32 x, U32 y, U32 r, U32 c){int i, j;for(j = 0; j < LCD_YSIZE; j++)for(i = 0; i < LCD_XSIZE; i++){if(((i-x)*(i-x)+(j-y)*(j-y))< r*r)LCD_BUFFER = c;}}void __irq ADC_ISR(void){//rADCDLY = 500000;if(rSUBSRCPND&(0x1<<9)){if(rADCDAT0 & 0x8000){DrawCircle(200, 200, 5, 0xFF0000);rADCTSC = 0xd3;}else{//Paint_background(0xff0000);DrawCircle(100, 100, 5, 0xFF0000);FlagTc = 1;rADCTSC &= 0xf0;rADCTSC |= (0x1<<3)|(0x1<<2);                      //设置自动转换模式,上拉禁止,无操作模式rADCDLY = 500000;rADCCON |= 0x1;}}elseif(rSUBSRCPND&(0x1<<10)){DrawCircle(150, 150, 5, 0x0);fuck = 1;xdata = rADCDAT0&0x3ff;ydata = rADCDAT1&0x3ff;rADCTSC = 0xd3;rADCTSC |= 0x1<<8;}rSUBSRCPND |= 0x1<<9;rSUBSRCPND |= 0x1<<10;rINTSUBMSK &= ~((0x1<<9)|(0x1<<10));rINTPND |= 0x1<<31;rSRCPND |= 0x1<<31;rINTMSK &= ~(0x1<<31);}void __irq IIC_ISR(void){       rSRCPND |= 0x1<<27;       rINTPND |= 0x1<<27;       flag = 0;   }   void wrat24c02(unsigned char add,unsigned char word, U32 length){       int i;       flag = 1;      Paint_background(0xff0000);    rIICDS = 0xa0;                //dev add      rIICCON &= ~(0x1<<4);         //清中断      rIICSTAT = 0xf0;            //主发送模式,写开始信号输出,IIC Rx/Tx使能      //等待ACK,接收器在接受到8位数据后,在第9个时钟周期,拉低SDA电平,然后会产生中断      while(flag == 1)                        delay(100);       flag = 1;       rIICDS = word;               //word add    发送要写入的数据的内存其实地址      rIICCON &= ~(0x1<<4);      while(flag)         delay(100);            //注意要有delay      for(i = 0; i < length; i++){         flag = 1;         rIICDS = iic_buffer;         rIICCON &= ~(0x1<<4);         while(flag)               delay(100);       }            rIICCON = 0xe0;            //IIC应答有效,IICCLK=fpclk/512,IIC接受发送中断使能位         rIICSTAT = 0xd0;             //主发送模式,rIICCON和rIICSTAT配置好,方便下次使用    }   void rdat24c02(unsigned char add, unsigned char word, U32 length){       int i;       char temp;       flag = 1;       rIICDS = add;            //dev add       rIICCON &= ~(0x1<<4);       rIICSTAT = 0xf0;       while(flag)         delay(100);       flag = 1;            rIICDS = word;         //word add       rIICCON &= ~(0x1<<4);       while(flag)         delay(100);       flag = 1;       //这里的IIC的随机读操作,根据IIC的随机读时序,先发启动,要读取的设备地址和写的内存地址,方向是写,即0,重启IIC,       //发要读取的设备地址,这次方向是读,然后接到ACK,从机向主机发data,主机相应ACK,直到最后一个data,主机不相应ACK,       //发送停止信号      rIICDS = add;            //dev add       rIICSTAT = 0xb0;         //改变方向为主接收      rIICCON &= ~(0x1<<4);       while(flag)         delay(100);       flag = 1;            temp = rIICDS;       rIICCON &= ~(0x1<<4);                  while(flag)         delay(100);            for(i = 0; i < length; i++){         flag = 1;         if(i == (length - 1)){               rIICCON &= ~(0x1<<7);         }         iic_buffer = rIICDS;         rIICCON &= ~(0x1<<4);         while(flag)               delay(100);       }            rIICCON = 0xd0;       rIICSTAT = 0x90;       delay(200);   } void Init_LCD(){   rLCDCON1=(CLKVAL<<8)|(MMODE<<7)|(PNRMODE<<5)|(BPPMODE<<1)|0;   //设置CLKVAL,VCLK=HCLK/[(CLKVAL+1)*2],决定VM的触发方式,选择显示模式和BPP模式,暂时不要开启LCD,因为还没有设置好       rLCDCON2=(VBPD<<24)|(LINEVAL<<14)|(VFPD<<6)|(VSPW);    //rLCDCON2,rLCDCON3和rLCDCON4主要设置时序         rLCDCON3=(HBPD<<19)|(HOZVAL<<8)|(HFPD);         rLCDCON4=(HSPW);         rLCDCON5 = (BPP24BL<<12) | (INVVCLK<<10) | (INVVLINE<<9) | (INVVFRAME<<8) | (0<<7) | (INVVDEN<<6) | (PWREN<<3)|(BSWP<<1) | (HWSWP);                         //INVVLINE和INVVFRAME需要进行翻转,因为CPU发出的是正脉冲,LCD使用的是负脉冲,所以要改变极性,PWREN使能电源信号       rLCDSADDR1=(((U32)LCD_BUFFER>>22)<<21)|M5D((U32)LCD_BUFFER>>1);         rLCDSADDR2=M5D(((U32)LCD_BUFFER+(SCR_XSIZE*SCR_YSIZE*4))>>1 );         rLCDSADDR3=PAGEWIDTH*32/16;         rLCDINTMSK|=(3);               rTCONSEL = 0;                  rGPCUP = 0x0;         rGPDCON = 0xaaaaaaaa;         rGPCCON = 0xaaaa02a9;         rGPDUP = 0x0;         rGPGUP=rGPGUP&(~(1<<4))|(1<<4);               rGPGCON=rGPGCON&(~(3<<8))|(3<<8);          rLCDCON1 |= 1;   //使能数据输出和LCD控制信号   }    void DrawCross(U32 x, U32 y, U32 c){int i;for(i = x - 15; i < x + 16; i++)LCD_BUFFER = c;for(i = y - 15; i < y + 16; i++)LCD_BUFFER = c;}void Paint_Ascii(U32 x, U32 y, U32 color, unsigned char ch[]){            int i, j, test;            for(i = 0; i < 16; i++){                test = 0x80;                for(j = 0; j < 8; j++){                  if(test & ch)                        LCD_BUFFER = color;                  test >>= 1;                }            }      }   void WtIic(U32 data, U32 wordadd){iic_buffer = (U8)(data&0xff);iic_buffer = (U8)((data>>8)&0xff);iic_buffer = (U8)((data>>16)&0xff);iic_buffer = (U8)((data>>24)&0xff);wrat24c02(0xa0,wordadd,4);}U32 rdIic(U32 wordadd){U32 data;rdat24c02(0xa0,wordadd,4);data = iic_buffer|(iic_buffer<<8)|(iic_buffer<<16)|(iic_buffer<<24);return data;}void revise(){int i;DrawCross(24,32,0xFF00FF);Paint_Ascii(32, 40, 0xFF00FF, &__ASCII['1'*16]);DrawCross(210,160,0xFF00FF);Paint_Ascii(218, 168, 0xFF00FF, &__ASCII['2'*16]);DrawCross(120,288,0xFF00FF);Paint_Ascii(128, 296, 0xFF00FF, &__ASCII['3'*16]);for(i = 0; i < 3; i++){while(FlagTc == 0)delay(500);//Paint_background(0xff0000);x = xdata;y = ydata;FlagTc = 0;//if(i == 0)Paint_background(0xff0000);//if(i == 2)Paint_background(0x0);}//Paint_background(0xff0000);/*K = (x-x)*(y-y)-(x-x)*(y-y);A = (24-120)*(y-y)-(210-120)*(y-y);B = (x-x)*(210-120)-(24-120)*(x-x);C = y*(x*210-x*120)+y*(x*120-x*24)+y*(x*24-x*210);D = (32-288)*(y-y)-(160-288)*(y-y);E = (x-x)*(160-288)-(32-288)*(x-x);F = y*(x*160-x*288)+y*(x*288-x*32)+y*(x*32-x*160);*/K=(x-x)*(y-y)-(x-x)*(y-y);A=(32-288)*(y-y)-(160-288)*(y-y);B=(x-x)*(160-288)-(32-288)*(x-x);C=y*(x*160-x*288)+y*(x*288-x*32)+y*(x*32-x*160);D=(24-120)*(y-y)-(210-120)*(y-y);E=(x-x)*(210-120)-(24-120)*(x-x);F=y*(x*210-x*120)+y*(x*120-x*24)+y*(x*24-x*210);//}int Main(){   count = 0;fuck = 0;Init_LCD();rSRCPND |= (0x1<<31)|(0x1<<27);rINTPND |= (0x1<<31)|(0x1<<27);rINTMSK &= ~((0x1<<31)|(0x1<<27));rSUBSRCPND |= (0x1<<9)|(0x1<<10);rINTSUBMSK &= ~((0x1<<9)|(0x1<<10));rADCTSC = 0xd3;rADCDLY = 50000;rADCCON = (1<<14)|(10<<9);rGPECON = 0xa0000000;rGPEUP = 0xc000;rIICCON = 0xe0;rIICSTAT = 0x10;pISR_ADC = (U32)ADC_ISR;pISR_IIC = (U32)IIC_ISR;       Paint_background(0xffffff);    for(i = 0; i < 8; i++)    iic_buffer = 0xff;    revise();   /*rdat24c02(0xa0,0x0,1);   //revise();    if(iic_buffer != 0xc7){    revise();    //Paint_background(0x0);    //Paint_background(0xff0000);    iic_buffer = 0xc7;    wrat24c02(0xa0,0x0,1);    Paint_background(0xff0000);    WtIic(A,0x10);    delay(500);    WtIic(B,0x20);    delay(500);    WtIic(C,0x30);    delay(500);    WtIic(D,0x40);    delay(500);    WtIic(E,0x50);    delay(500);    WtIic(F,0x60);    delay(500);    }    else{    A = rdIic(0x10);    delay(500);    B = rdIic(0x20);    delay(500);    C = rdIic(0x30);    delay(500);    D = rdIic(0x40);    delay(500);    E = rdIic(0x50);    delay(500);    F = rdIic(0x60);    delay(500);    }*/    //Paint_background(0x0);    delay(9999);    Paint_background(0xffffff);    while(1){    if(FlagTc == 1){    //delay(10000);    xx = (A * xdata + B * ydata + C) / K;    yy = (D * xdata + E * ydata + F) / K;    DrawCircle(xx, yy, 5, 0xFF0000);    FlagTc = 0;    }    delay(100000);    }   /* while(1){    if(FlagTc == 1){    xx = (A * xdata + B * ydata + C) / K;    yy = (D * xdata + E * ydata + F) / K;    DrawCircle(xx, yy, 5, 0xFF0000);    FlagTc = 0;    }    delay(1000000);    }*/    //while(1);    }
页: [1]
查看完整版本: S3C2440-触摸屏