C8051F020程序库.docx

上传人:b****5 文档编号:6805517 上传时间:2023-01-10 格式:DOCX 页数:41 大小:25.89KB
下载 相关 举报
C8051F020程序库.docx_第1页
第1页 / 共41页
C8051F020程序库.docx_第2页
第2页 / 共41页
C8051F020程序库.docx_第3页
第3页 / 共41页
C8051F020程序库.docx_第4页
第4页 / 共41页
C8051F020程序库.docx_第5页
第5页 / 共41页
点击查看更多>>
下载资源
资源描述

C8051F020程序库.docx

《C8051F020程序库.docx》由会员分享,可在线阅读,更多相关《C8051F020程序库.docx(41页珍藏版)》请在冰豆网上搜索。

C8051F020程序库.docx

C8051F020程序库

240128的程序

#include

#include

#include

//

//

sfr16DP      =0x82;                //datapointer

sfr16TMR3RL  =0x92;                //Timer3reloadvalue

sfr16TMR3    =0x94;                //Timer3counter

sfr16ADC0    =0xbe;                //ADC0data

sfr16ADC0GT  =0xc4;                //ADC0greaterthanwindow

sfr16ADC0LT  =0xc6;                //ADC0lessthanwindow

sfr16RCAP2   =0xca;                //Timer2capture/reload

sfr16T2      =0xcc;                //Timer2

sfr16RCAP4   =0xe4;                //Timer4capture/reload

sfr16T4      =0xf4;                //Timer4

sfr16DAC0    =0xd2;                //DAC0data

sfr16DAC1    =0xd5;                //DAC1data

//

unsignedintad_temp,dis_y=0;

unsignedcharad_i=0;

chartabc;

unsignedchardis_i,dis_k=0;

//

unsignedchart_count,t_i;

unsignedintt_timecount;

bitt_flag;

unsignedlongt_y=0;

//

  

 voidSYSCLK_Init(void)

{

  unsignedinti;                             //delaycounter

  OSCXCN=0x67;                     //startexternaloscillatorwith

  for(i=0;i<3000;i++);          //Waitforosc.tostartup

  while(!

(OSCXCN&0x80));         //Waitforcrystalosc.tosettle

  OSCICN=0x88;   

 }

//-----------------------------------------------------------------------------

//函数名称:

     PORT_Init ()

//函数功能:

     通用I/O口及交叉开关初始化

//入口参数:

     无

//出口参数:

     无

//全局变量引用:

 无

//调用模块:

     无 

//-----------------------------------------------------------------------------

voidPORT_Init(void)

{

  XBR1     =0x02;

  XBR2    =0x40;

  P74OUT =0x0f;                      //P2口设为推挽方式

  P4=0x07;

}

//

voidT_Init(void)

{

 CKCON=0X18;

TMOD=0x15;

IP=0x0a;

TH0=0;

TL0=0;

TH1=(65536-44237)/256;

TL1=(65536-44237)%256;

TR1=1;

TR0=1;

ET0=1;

ET1=1;

 }

//ADC0配置,T3定时启动ADC

//-----------------------------------------------------------------------------

voidADC0_Init(void)

{

  ADC0CN=0x00;                     //ADC0向AD0BUSY写1时采样,左对齐

  REF0CN=0x03;                     //启用内部基准源

  ADC0CF=0X40;

  AMX0SL=0x01;

  AD0EN=1;            //选择采样输入源

  EIE2|=0x02;                      //启用ADC中断

}

//

voidt0(void)interrupt1

{

t_count++;

}

voidt1(void)interrupt3

{

TH1=(65536-44237)/256;

TL1=(65536-44237)%256;

t_timecount++;

if(t_timecount==250)

{

TR0=0;

t_timecount=0;

t_flag=1;

}

}

//ADC0采样中断

//-----------------------------------------------------------------------------

voidADC0_ISR(void)interrupt15

{

               

  AD0INT=0;  //清ADC中断标志位

  ad_temp=((ADC0H*256+ADC0L)*13)>>10;        

  tab_wave[ad_i]=(unsignedchar)(ad_temp&0xff);

  ad_i++;

  if(ad_i>=216){ad_i=0;AD0EN=0;}

  AD0BUSY=1;

}

//

//-----------------------------------------------------------------------------

//主程序

//-----------------------------------------------------------------------------

voidmain(void)

 { 

   WDTCN=0xde;

   WDTCN=0xad;                       //禁止看门狗定时器

   SYSCLK_Init();                        //系统时钟初始化

   PORT_Init();

   ADC0_Init();

   T_Init();

   lcd_int1();

   wtcd2(0x24,0x0000);

   show_coor(X_length,Y_length,origin_X,origin_Y,0,0);

   showxy();

   displayword(0,112,tab_word,2);

 displayword(13,112,tab_word+64,2);

 displaychar(6,112,tab_char+48,1);

 displaychar(10,112,tab_char+64,1);

 displaychar(23,112,tab_char+80,2);

 AD0BUSY=1;

 EA=1;

 while

(1)

 {

 

 

 //幅度显示

  if(AD0EN==0)

 {

 show_wave

(1);

 for(dis_i=0,dis_k=0;dis_i<216;dis_i++)

 if(tab_wave[dis_i]>dis_k)dis_k=tab_wave[dis_i];

 dis_y=(unsignedint)dis_k;

 dis_y=(dis_y*755)>>4;

 //dis_y=dis_y>>8;

 displaychar(5,112,tab_number+(dis_y/1000%10)*16,1);

 displaychar(7,112,tab_number+(dis_y/100%10)*16,1);

 displaychar(8,112,tab_number+(dis_y/10%10)*16,1);

 displaychar(9,112,tab_number+(dis_y%10)*16,1);

 //

 //计数显示

 for(t_i=0;t_i<6;t_i++)

 {

  if(t_flag==1)

   {

  t_flag=0;

     t_y=(t_count*65536+TH0*256+TL0)*2;

     t_timecount=0;

     t_count=0;

  TH0=0;

     TL0=0;

     TR0=1;

  }

 displaychar(18,112,tab_number+(t_y/10000%10)*16,1);

 displaychar(19,112,tab_number+(t_y/1000%10)*16,1);

 displaychar(20,112,tab_number+(t_y/100%10)*16,1);

 displaychar(21,112,tab_number+(t_y/10%10)*16,1);

 displaychar(22,112,tab_number+(t_y%10)*16,1);

 }

 //

 show_wave(0);

 show_coor(X_length,Y_length,origin_X,origin_Y,0,0);

 showxy();

 AD0EN=1;

 AD0BUSY=1;

 }

 }

}

---------------------------------------------------------------------------------------------------------------

dis240128.c文件

--------------------------------------------------------------------------------------------------------------

#defineX_length216      //xway

#defineY_length106   //yway

#defineorigin_X0   //原点x(绝对坐标)

#defineorigin_Y53   //原点y(绝对坐标)y为53

//

unsignedcharcklcdst(void)

{

 unsignedchartemp;

 P5=0xFF;

 P4=0x03;

 temp=P5;

 P4=0x07;

 returntemp;

}

//

voidcheck01(void)//状态位STA1,STA0判断(读写指令和读写数据)

{

   

   while(cklcdst()&0x03!

=0x03);

 

   

}

//

/*

voidcheck3(void)//状态位ST3判断(数据自动写状态)

{

   

 while(cklcdst()&0x08!

=0x08);

}

//

voidcheck2(void)//状态位ST2判断(数据自动读状态)

{

   

   while(cklcdst()&0x04!

=0x04);

  

}

//

voidcheck6(void)//状态位ST6判断(屏读/屏拷贝状态)

{

   

 while(cklcdst()&0x40!

=0x40);

}

//

voiddelay1000(unsignedchardelayvalue)

{

 unsignedchari;

 unsignedintj;

 i=delayvalue;       

 while(i--)

 {

  j=1000;       

  while(j--);

 }

}

//

voidawtdt0(unsignedcharuData)//自动写数据

{

   check3();

   wtdt(uData);

}

*/

//

voiddelay50(unsignedchardelayvalue)

{

 unsignedchari,j;

 i=delayvalue;      

 while(i--)

 {

  j=50;       

  while(j--);

 }

}//

voidwtcd(unsignedcharcmd)

{

 P4=0x05;

 P5=cmd;

 P4=0x07;

 delay50

(1);

}

//------------------------------------------------------------------------------

//IO口方式写数据

//------------------------------------------------------------------------------

//status:

O.K.

voidwtdt(unsignedcharlcddata)

{

 P4=0x04;

 P5=lcddata;

 P4=0x06;

 delay50

(1);

}

//

voidwtcd2(unsignedcharuCmd,unsignedintuPar)//写双参数的指令

{

   check01();

   wtdt(uPar&0xFF);//先写低字节,再写高字节

   check01();

   wtdt((unsignedchar)(uPar>>8));

   check01();

   wtcd(uCmd);

}

/********************

//=函数原型:

ucharwr_cmd_1(ucharuCmd,ucharuPar1)

//=功   能:

给T6963C写带单参数的指令

//=参   数:

//=返回值:

返回0成功,否则忙

//=函数性质:

私有函数

********************/

voidwtcd1(unsignedcharuCmd,unsignedcharuPar)//写单参数的指令

{

   check01();

   wtdt(uPar);

   check01();

   wtcd(uCmd);

}

//

voidwtcd0(unsignedcharuCmd)//写无参数的指令

{

   check01();

   wtcd(uCmd);

}

//

voidwtdt0(unsignedcharuData)//写一次数据

{

   check01();

   wtdt(uData);

}

//

voidlcdclr()

{ unsignedchari,j;

  wtcd2(0x24,0x0000);

  wtcd0(0xb0);

  for(j=0;j<=0x80;j++)

  for(i=0;i<=0x1E;i++)

  wtdt0(0x00);

  wtcd0(0xb2);

}

//----------------------------------------------------------------------------------

//----------------------------------------------------------------------------------

//初始化函数

voidlcd_int1()

 {lcdclr(); //清屏

  wtcd2(0x42,0x0000);

  wtcd2(0x43,0x001e); //图形显示宽度30

  wtcd2(0x24,0x0000);

  wtcd0(0x80);  //显示方式OR功能

  wtcd0(0x98);   //启用图形显示方式,光标闪烁

 }

 //

voidprintpoint(unsignedcharPointX,unsignedcharPointY,bitflag)

{

 unsignedintk=0;

 unsignedcharldata=0xf0;

//bitoperation :

flag=0bitresetandflag=1bitset;(7-PointY%8)isselect bit.

  k=PointY*30+PointX/8; //ksavetheaddress

 ldata=ldata+7-PointX%8;

 if(flag)ldata=ldata|0x08;

 wtcd2(0x24,k);

   wtcd0(ldata); //outputthebitoperation

}

//--------------------------------------------------------------------------

voidshow_coor(unsignedcharx_length,unsignedchary_length,unsignedcharorigin_x,unsignedcharorigin_y,bitoffset,bitoffset1) 

 {

 unsignedchari,j,k,l,m;

  //showcoordinatestartpoint

 if((offset==0)&&(offset1==0))

  {j=origin_x;        

   k=x_length+origin_x+6;     

    l=origin_y-y_length/2;    

     m=y_length+origin_y-y_length/2+3;//ywaylength

  }

  elseif((offset==0)&&(offset1==1))

   {

   j=origin_x;        

    k=x_length+origin_x+6;     

     l=origin_y;    

      m=y_length+origin_y+3;

   }

   elseif((offset==1)&&(offset1==0))

    {

    j=origin_x;        

    k=x_length+origin_x+6;     

     l=origin_y-y_length;    

                       m=y_length+origin_y-y_length+3;

  

    }

     

 //showthecoordinate

 for(i=j;i

     printpoint(i,origin_y,1);

  

 for(i=l;i

     printpoint(origin_x,i,1);

  

 for(i=l;i

    {

  printpoint(origin_x+1,i,1);  

  }

 

  for(i=j;i

    { printpoint(i,origin_y-1,1);

     

   }

   printpoint(i-1,origin_y-1,1);//xwaythenextpoint

 }

//----------------------------------------------------------------------------------

voidshow_wave(bitmod)

//                           y       0            1

{ unsignedchari,k;

  for(i=1;i

    { 

  k=origin_Y-tab_wave[i];

  if(k!

=origin_Y)printpoint(origin_X+i,k,mod);

  

 }

}

//汉化显示程序,y为行,x为列,注意一个汉字占两列,而西文字符占一列

 voiddisplayword(unsignedcharx,unsignedchary,unsignedchar*word,unsignedcharc)

 {

  unsignedintxy;

 unsignedchari,j,k=0;

 xy=y*30+x;

 for(i=0;i

 for(j=0;j<16;j++)

 {

 wtcd2(0x24,xy+j*30+i*2);//置地址指针 lowaddress

  wtcd1(0xc0,word[k]);

 wtcd1(0xc0,word[k+1]);

 k+=2;

 }

}

//字符显示程序,y为行,x为列,注意一个汉字占两列,而西文字符占一列

 voiddisplaychar(unsignedcharx,unsignedchary,unsignedchar*word,unsignedcharc)

 {

  unsignedintxy;

 unsigned

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 法律文书 > 调解书

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1