void disp_0(unsigned char x,unsigned char y)
{
Lcd_PutPixel(x+1,y+1,1);
Lcd_PutPixel(x+1,y+2,1);
Lcd_PutPixel(x+1,y+3,1);
Lcd_PutPixel(x+2,y+0,1);
Lcd_PutPixel(x+2,y+4,1);
Lcd_PutPixel(x+3,y+1,1);
Lcd_PutPixel(x+3,y+2,1);
Lcd_PutPixel(x+3,y+3,1);
}
這一段程序不知道是在畫什么圖。
在程序中看到了ADC采集程序,沒有看到轉換啊
還有主函數中:
case 0:
delnop=1;
disp_p(91,54);
clr(66,54,71,57);
clr(41,54,46,57);
clr(16,54,21,57);
這是在畫什么呢?
程序附上,感謝各位大哥解答!
- #include <STC12c5a.H>
- #include<intrins.h>
- #include<math.h>
- sbit RS=P2^5;
- sbit RW=P2^6;
- sbit E=P2^7;
- sbit led=P1^0;
- sbit jiakey=P3^0;
- sbit jiankey=P3^1;
- sbit ledkey=P3^2;
- #define LcdData P0
- unsigned char dati=0;
- unsigned char dat[100];
- unsigned char over=0;
- unsigned int temp=0;
- unsigned char mode=0;
- unsigned int delnop=0;
- //////////////////////////////////////
- unsigned char Lcd_CheckBusy(void)
- {
- unsigned char Busy;
- LcdData=0xff;
- RS=0;
- RW=1;
- E=1;
- _nop_();
- Busy=LcdData&0x80;
- E=0;
- return Busy;
- }
- void Lcd_WriteData(unsigned char Data)
- {
- while(Lcd_CheckBusy());
- RS=1;
- RW=0;
- E=0;
- _nop_();
- _nop_();
- LcdData=Data;
- E=1;
- _nop_();
- _nop_();
- E=0;
- }
- unsigned char Lcd_ReadData(void)
- {
- unsigned char Temp;
- while(Lcd_CheckBusy());
- LcdData=0xff;
- RS=1;
- RW=1;
- E=1;
- _nop_();
- Temp=LcdData;
- E=0;
- return Temp;
- }
- void Lcd_WriteCmd(unsigned char CmdCode)
- {
- while(Lcd_CheckBusy());
- RS=0;
- RW=0;
- E=0;
- _nop_();
- _nop_();
- LcdData=CmdCode;
- _nop_();
- _nop_();
- E=1;
- _nop_();
- _nop_();
- E=0;
- }
- code unsigned int LcdMaskTab[]={0x0001,0x0002,0x0004,0x0008,0x0010,0x0020,0x0040,0x0080,0x0100,0x0200,0x0400,0x0800,0x1000,0x2000,0x4000,0x8000};
- void Lcd_PutPixel(unsigned char x,unsigned char y,unsigned char Color)
- {
- unsigned char z,w;
- unsigned int Temp;
- if(x>=128||y>=64)
- return;
- Color=Color%2;
- w=15-x%16;
- x=x/16;
- if(y<32)
- z=0x80;
- else
- z=0x88;
- y=y%32;
-
- Lcd_WriteCmd(0x36);
- Lcd_WriteCmd(y+0x80);
- Lcd_WriteCmd(x+z);
- Temp=Lcd_ReadData();
- Temp=(unsigned int)Lcd_ReadData()<<8;
- Temp|=(unsigned int)Lcd_ReadData();
-
- if(Color==1)
- Temp|=LcdMaskTab[w];
- else
- Temp&=~LcdMaskTab[w];
-
- Lcd_WriteCmd(y+0x80);
- Lcd_WriteCmd(x+z);
- Lcd_WriteData(Temp>>8);
- Lcd_WriteData(Temp&0x00ff);
- Lcd_WriteCmd(0x30);
-
- }
-
- void Lcd_Clear(unsigned char Mode)
- {
- unsigned char x,y,ii;
- unsigned char Temp;
- if(Mode%2==0)
- Temp=0x00;
- else
- Temp=0xff;
- Lcd_WriteCmd(0x36);
- for(ii=0;ii<9;ii+=8)
- for(y=0;y<0x20;y++)
- for(x=0;x<8;x++)
- {
-
- Lcd_WriteCmd(y+0x80);
- Lcd_WriteCmd(x+0x80+ii);
- Lcd_WriteData(Temp);
- Lcd_WriteData(Temp);
-
- }
- Lcd_WriteCmd(0x30);
- }
-
- void Lcd_Reset()
- {
- Lcd_WriteCmd(0x30);
- Lcd_WriteCmd(0x0c);
- Lcd_WriteCmd(0x01);
- Lcd_WriteCmd(0x06);
- }
- //////////////////////////////////////
- void InitADC()
- {
- P1ASF=0X80;
- ADC_RES=0;
- ADC_CONTR=0xef;
- EADC=1;
- }
- void adc_isr() interrupt 5 using 1
- {
- ADC_CONTR=0xef;
- if(over==0)
- {
- temp=delnop;
- while(temp)
- {
- temp--;
- }
- dat[dati]=ADC_RES;
- dati++;
- if(dati>100)
- {
- dati=0;
- over=1;
- }
- }
- }
- //////////////////////////////////////
- void disp_0(unsigned char x,unsigned char y)
- {
- Lcd_PutPixel(x+1,y+1,1);
- Lcd_PutPixel(x+1,y+2,1);
- Lcd_PutPixel(x+1,y+3,1);
- Lcd_PutPixel(x+2,y+0,1);
- Lcd_PutPixel(x+2,y+4,1);
- Lcd_PutPixel(x+3,y+1,1);
- Lcd_PutPixel(x+3,y+2,1);
- Lcd_PutPixel(x+3,y+3,1);
- }
- void disp_1(unsigned char x,unsigned char y)
- {
- Lcd_PutPixel(x+1,y+1,1);
- Lcd_PutPixel(x+1,y+4,1);
- Lcd_PutPixel(x+2,y+0,1);
- Lcd_PutPixel(x+2,y+1,1);
- Lcd_PutPixel(x+2,y+2,1);
- Lcd_PutPixel(x+2,y+3,1);
- Lcd_PutPixel(x+2,y+4,1);
- Lcd_PutPixel(x+3,y+4,1);
- }
- void disp_2(unsigned char x,unsigned char y)
- {
- Lcd_PutPixel(x+1,y+0,1);
- Lcd_PutPixel(x+1,y+2,1);
- Lcd_PutPixel(x+1,y+3,1);
- Lcd_PutPixel(x+1,y+4,1);
- Lcd_PutPixel(x+2,y+0,1);
- Lcd_PutPixel(x+2,y+2,1);
- Lcd_PutPixel(x+2,y+4,1);
- Lcd_PutPixel(x+3,y+0,1);
- Lcd_PutPixel(x+3,y+1,1);
- Lcd_PutPixel(x+3,y+2,1);
- Lcd_PutPixel(x+3,y+4,1);
- }
- void disp_3(unsigned char x,unsigned char y)
- {
- Lcd_PutPixel(x+1,y+0,1);
- Lcd_PutPixel(x+1,y+2,1);
- Lcd_PutPixel(x+1,y+4,1);
- Lcd_PutPixel(x+2,y+0,1);
- Lcd_PutPixel(x+2,y+2,1);
- Lcd_PutPixel(x+2,y+4,1);
- Lcd_PutPixel(x+3,y+0,1);
- Lcd_PutPixel(x+3,y+1,1);
- Lcd_PutPixel(x+3,y+2,1);
- Lcd_PutPixel(x+3,y+3,1);
- Lcd_PutPixel(x+3,y+4,1);
- }
- void disp_4(unsigned char x,unsigned char y)
- {
- Lcd_PutPixel(x+1,y+0,1);
- Lcd_PutPixel(x+1,y+1,1);
- Lcd_PutPixel(x+1,y+2,1);
- Lcd_PutPixel(x+2,y+2,1);
- Lcd_PutPixel(x+3,y+0,1);
- Lcd_PutPixel(x+3,y+1,1);
- Lcd_PutPixel(x+3,y+2,1);
- Lcd_PutPixel(x+3,y+3,1);
- Lcd_PutPixel(x+3,y+4,1);
- }
- void disp_5(unsigned char x,unsigned char y)
- {
- Lcd_PutPixel(x+1,y+0,1);
- Lcd_PutPixel(x+1,y+1,1);
- Lcd_PutPixel(x+1,y+2,1);
- Lcd_PutPixel(x+1,y+4,1);
- Lcd_PutPixel(x+2,y+0,1);
- Lcd_PutPixel(x+2,y+2,1);
- Lcd_PutPixel(x+2,y+4,1);
- Lcd_PutPixel(x+3,y+0,1);
- Lcd_PutPixel(x+3,y+2,1);
- Lcd_PutPixel(x+3,y+3,1);
- Lcd_PutPixel(x+3,y+4,1);
- }
- void disp_p(unsigned char x,unsigned char y)
- {
- Lcd_PutPixel(x+0,y+0,1);
- Lcd_PutPixel(x+1,y+0,1);
- Lcd_PutPixel(x+1,y+1,1);
- Lcd_PutPixel(x+2,y+0,1);
- Lcd_PutPixel(x+2,y+1,1);
- Lcd_PutPixel(x+2,y+2,1);
- Lcd_PutPixel(x+3,y+0,1);
- Lcd_PutPixel(x+3,y+1,1);
- Lcd_PutPixel(x+4,y+0,1);
- }
- void disp_k(unsigned char x,unsigned char y)
- {
- Lcd_PutPixel(x+0,y+0,1);
- Lcd_PutPixel(x+0,y+1,1);
- Lcd_PutPixel(x+0,y+2,1);
- Lcd_PutPixel(x+0,y+3,1);
- Lcd_PutPixel(x+0,y+4,1);
- Lcd_PutPixel(x+1,y+2,1);
- Lcd_PutPixel(x+2,y+1,1);
- Lcd_PutPixel(x+2,y+3,1);
- Lcd_PutPixel(x+3,y+0,1);
- Lcd_PutPixel(x+3,y+4,1);
- }
- void disp_hz(unsigned char x,unsigned char y)
- {
- Lcd_PutPixel(x+0,y+0,1);
- Lcd_PutPixel(x+0,y+1,1);
- Lcd_PutPixel(x+0,y+2,1);
- Lcd_PutPixel(x+0,y+3,1);
- Lcd_PutPixel(x+0,y+4,1);
- Lcd_PutPixel(x+1,y+2,1);
- Lcd_PutPixel(x+2,y+0,1);
- Lcd_PutPixel(x+2,y+1,1);
- Lcd_PutPixel(x+2,y+2,1);
- Lcd_PutPixel(x+2,y+3,1);
- Lcd_PutPixel(x+2,y+4,1);
- Lcd_PutPixel(x+4,y+1,1);
- Lcd_PutPixel(x+4,y+3,1);
- Lcd_PutPixel(x+4,y+4,1);
- Lcd_PutPixel(x+5,y+1,1);
- Lcd_PutPixel(x+5,y+2,1);
- Lcd_PutPixel(x+5,y+4,1);
- }
- void disp_ledon(unsigned char x,unsigned char y)
- {
- Lcd_PutPixel(x+1,y+0,1);
- Lcd_PutPixel(x+1,y+1,1);
- Lcd_PutPixel(x+1,y+2,1);
- Lcd_PutPixel(x+1,y+3,1);
- Lcd_PutPixel(x+1,y+4,1);
- Lcd_PutPixel(x+2,y+1,1);
- Lcd_PutPixel(x+2,y+2,1);
- Lcd_PutPixel(x+2,y+3,1);
- Lcd_PutPixel(x+3,y+0,1);
- Lcd_PutPixel(x+3,y+4,1);
- Lcd_PutPixel(x+4,y+2,1);
- }
- void disp_ledoff(unsigned char x,unsigned char y)
- {
- Lcd_PutPixel(x+1,y+0,1);
- Lcd_PutPixel(x+1,y+1,1);
- Lcd_PutPixel(x+1,y+2,1);
- Lcd_PutPixel(x+1,y+3,1);
- Lcd_PutPixel(x+1,y+4,1);
- Lcd_PutPixel(x+2,y+1,1);
- Lcd_PutPixel(x+2,y+2,1);
- Lcd_PutPixel(x+2,y+3,1);
- }
- void clr(unsigned char starx,unsigned char stary,unsigned char endx,unsigned char endy)
- {
- char x=0;
- char y=0;
- for(x=starx;x<endx;x++)
- {
- for(y=stary;y<endy;y++)
- {
- Lcd_PutPixel(x,y,0);
- }
- }
- }
- void disp_bj(void)
- {
- unsigned char x=0;
- unsigned char y=0;
- for(x=13;x<114;x++)
- {
- Lcd_PutPixel(x,52,1);
- }
- for(y=0;y<52;y++)
- {
- Lcd_PutPixel(13,y,1);
- }
- for(y=0;y<52;y++)
- {
- #include <REGX51.H>
- Lcd_PutPixel(114,y,1);
- }
- Lcd_PutPixel(13,51,0);
- Lcd_PutPixel(13,41,0);
- Lcd_PutPixel(13,31,0);
- Lcd_PutPixel(13,21,0);
- Lcd_PutPixel(13,11,0);
- Lcd_PutPixel(13,1,0);
- Lcd_PutPixel(114,51,0);
- Lcd_PutPixel(114,41,0);
- Lcd_PutPixel(114,31,0);
- Lcd_PutPixel(114,21,0);
- Lcd_PutPixel(114,11,0);
- Lcd_PutPixel(114,1,0);
- disp_0(5,50);
- disp_1(5,40);
- disp_2(5,30);
- disp_3(5,20);
- disp_4(5,10);
- disp_5(5,0);
- disp_0(117,50);
- disp_1(117,40);
- disp_2(117,30);
- disp_3(117,20);
- disp_4(117,10);
- disp_5(117,0);
- disp_2(13,58);
- disp_hz(18,58);
- disp_2(38,58);
- disp_0(43,58);
- disp_hz(48,58);
- disp_2(63,58);
- disp_0(68,58);
- disp_0(73,58);
- disp_hz(78,58);
- disp_2(88,58);
- disp_k(93,58);
- disp_hz(98,58);
- }
- void line(unsigned char x0,unsigned char y0,unsigned char x1,unsigned char y1)
- {
- int i,dx,dy,e,x,y;
- Lcd_PutPixel(x0,y0,1);
- Lcd_PutPixel(x1,y1,1);
- dx=x1-x0;
- dy=y1-y0;
- x=x0;
- y=y0;
- if(dx>0&&dy>0)
- {
- if(dx>dy)
- {
- e=-dx;
- for(i=0;i<dx;i++)
- {
- Lcd_PutPixel(x,y,1);
- x++;
- e=e+2*dy;
- if(e>=0)
- {
- y++;
- e=e-2*dx;
- }
- }
- }
- else
- {
- e=-dy;
- x=x0;
- y=y0;
- for(i=0;i<dy;i++)
- {
- Lcd_PutPixel(x,y,1);
- y++;
- e=e+2*dx;
- if(e>=0)
- {
- x++;
- e=e-2*dy;
- }
- }
- }
- }
- if(dx<0&&dy<0)
- {
- dx=x0-x1;
- dy=y0-y1;
- if(dx>dy)
- {
- e=-dx;
- for(i=0;i<dx;i++)
- {
- Lcd_PutPixel(x,y,1);
- x--;
- e=e+2*dy;
- if(e>=0)
- {
- y--;
- e=e-2*dx;
- }
- }
- }
- else
- {
- e=-dy;
- for(i=0;i<dy;i++)
- {
- Lcd_PutPixel(x,y,1);
- y--;
- e=e+2*dx;
- if(e>=0)
- {
- x--;
- e=e-2*dy;
- }
- }
- }
- }
- if(dx>0&&dy<0)
- {
- dy=y0-y1;
- if(dx>dy)
- {
- e=-dx;
- for(i=0;i<dx;i++)
- {
- Lcd_PutPixel(x,y,1);
- x++;
- e=e+2*dy;
- if(e>=0)
- {
- y--;
- e=e-2*dx;
- }
- }
- }
- else
- {
- e=-dy;
- for(i=0;i<dy;i++)
- {
- Lcd_PutPixel(x,y,1);
- y--;
- e=e+2*dx;
- if(e>=0)
- {
- x++;
- e=e-2*dy;
- }
- }
- }
- }
- if(dx<0&&dy>0)
- {
- dx=x0-x1;
- if(dx>dy)
- {
- e=-dx;
- for(i=0;i<dx;i++)
- {
- Lcd_PutPixel(x,y,1);
- x--;
- e=e+2*dy;
- if(e>=0)
- {
- y++;
- e=e-2*dx;
- }
- }
- }
- else
- {
- e=-dy;
- for(i=0;i<dy;i++)
- {
- Lcd_PutPixel(x,y,1);
- y++;
- e=e+2*dx;
- if(e>=0)
- {
- x--;
- e=e-2*dy;
- }
- }
- }
- }
- if(dx!=0&&dy==0)
- {
- if(dx>0)
- {
- for(i=0;i<dx;i++)
- {
- Lcd_PutPixel(x,y,1);
- x++;
- }
- }
- else
- {
- dx=x0-x1;
- for(i=0;i<dx;i++)
- {
- Lcd_PutPixel(x,y,1);
- x--;
- }
- }
- }
- if(dx==0&&dy!=0)
- {
- if(dy>0)
- {
- for(i=0;i<dy;i++)
- {
- Lcd_PutPixel(x,y,1);
- y++;
- }
- }
- else
- {
- dy=y0-y1;
- for(i=0;i<dy;i++)
- {
- Lcd_PutPixel(x,y,1);
- y--;
- }
- }
- }
- }
- void disp_ware()
- {
- unsigned char x=0;
- unsigned char y=0;
- clr(14,0,15,52);
- for(x=1;x<100;x++)
- {
- clr(x+14,0,x+15,52);
- line(x+13,51-(dat[x-1]/5),x+14,51-(dat[x]/5));
- }
- }
- //////////////////////////////////////
- main()
- {
- Lcd_Reset();
- Lcd_Clear(0);
- InitADC();
- disp_bj();
- EA=1;
- while(1)
- {
- if(over)
- {
- disp_ware();
- if(ledkey==0)
- {
- led=~led;
- }
- if(jiakey==0)
- {
- if(mode<3)
- {
- mode++;
- }
- }
- if(jiankey==0)
- {
- if(mode>0)
- {
- mode--;
- }
- }
- if(led)
- {
- clr(5,58,10,63);
- disp_ledon(5,58);
- }
- else
- {
- clr(5,58,10,63);
- disp_ledoff(5,58);
- }
- switch(mode)
- {
- case 0:
- delnop=1;
- disp_p(91,54);
- clr(66,54,71,57);
- clr(41,54,46,57);
- clr(16,54,21,57);
- break;
- case 1:
- delnop=40;
- disp_p(66,54);
- clr(91,54,96,57);
- clr(41,54,46,57);
- clr(16,54,21,57);
- break;
- case 2:
- delnop=440;
- disp_p(41,54);
- clr(91,54,96,57);
- clr(66,54,71,57);
- clr(16,54,21,57);
- break;
- case 3:
- delnop=4440;
- disp_p(16,54);
- clr(91,54,96,57);
- clr(41,54,46,57);
- clr(66,54,71,57);
- break;
- default:
- break;
- }
- over=0;
- }
- }
- }
復制代碼 |