这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » DIY与开源设计 » 电子DIY » goodboy3021 MCU DIY进程帖

共53条 2/6 1 2 3 4 5 6 ›| 跳转至
专家
2011-12-03 13:24:10     打赏
11楼

板子已经焊接了一部分,为了测试一下焊接得有没有问题,先做了一个流水灯实验:






#include<STC12C5A60S2.H> //头文件

/*********************************************************************************************
函数名:毫秒级CPU延时函数
调  用:DELAY_MS (?);
参  数:1~65535(参数不可为0)
返回值:无
结  果:占用CPU方式延时与参数数值相同的毫秒时间
备  注:应用于1T单片机时i<600,应用于12T单片机时i<125
/*********************************************************************************************/
void DELAY_MS (unsigned int a){
 unsigned int i;
 while( a-- != 0){
  for(i = 0; i < 600; i++);
 }
}
/*********************************************************************************************/


/*********************************************************************************************/
void main (void){ //主程序
unsigned char i;
 while(1){

  for(i=0;i<8;i++){ //低位到高位流动(P1.0~P1.7)
   P1 = 1<<i;
   DELAY_MS(100); 
      }
  P1=0x00;

  for(i=0;i<8;i++){ //高位到低位流动(P1.7~P1.0)
   P1 = 1<<7-i;
   DELAY_MS(100); 
  }
  P1=0x00;
 }
}
/*********************************************************************************************/


专家
2011-12-03 13:27:58     打赏
12楼
ATmega8515这个没用个,但是我看了一下,管脚好像是兼容的,兼容的话就可以的

专家
2011-12-03 18:12:25     打赏
13楼
显摆一下我的STC单片机USB转232下载线:


专家
2011-12-04 06:34:13     打赏
14楼

LED数码管简单测试:





程序:
#include<STC12C5A60S2.H> //头文件
unsigned char  display[11]  =
{ 0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f, 0x80};//显示码数组
/*********************************************************************************************
函数名:毫秒级CPU延时函数
调  用:DELAY_MS (?);
参  数:1~65535(参数不可为0)
返回值:无
结  果:占用CPU方式延时与参数数值相同的毫秒时间
备  注:应用于1T单片机时i<600,应用于12T单片机时i<125
/*********************************************************************************************/
void DELAY_MS (unsigned int a){
 unsigned int i;
 while( a-- != 0){
  for(i = 0; i < 600; i++);
 }
}
/*********************************************************************************************/


/*********************************************************************************************/
void main (void){ //主程序
unsigned char i,j,k;
 while(1){
     for(i=0;i<11;i++)
     {
          P0 = display[i];
       for(k=0;k<100;k++)
       {
         for(j=0;j<8;j++){ //低位到高位流动(P1.0~P1.7)
      P2 = j;
      DELAY_MS(1); 
          }
      }
   }
 }
}
/*********************************************************************************************/


专家
2011-12-04 10:05:49     打赏
15楼

点亮开发板上的LCM1602液晶:



简单程序:
#include<STC12C5A60S2.H> //头文件

typedef unsigned char      uint8;          // 无符号8位整型变量 //

/********************************************************************************************
// 引脚定义 //
/********************************************************************************************/
#define  LCM1602_DB0_DB7  P0   // 定义LCM1602的数据总线
sbit LCM1602_RS   = P2 ^ 4;     // 定义LCM1602的RS控制线
sbit LCM1602_RW   = P2 ^ 5;     // 定义LCM1602的RW控制线
sbit LCM1602_E    = P2 ^ 6;     // 定义LCM1602的E控制线
sbit LCM1602_Busy = P0 ^ 7;     // 定义LCM1602的测忙线(与LCM1602_DB0_DB7关联)
/********************************************************************************************
// 定义LCM1602指令集 //
/********************************************************************************************/
#define   CMD_clear  0x01             // 清除屏幕
#define   CMD_back  0x02             // DDRAM回零位
#define   CMD_dec1  0x04             // 读入后AC(指针)减1,向左写
#define   CMD_add1  0x06             // 读入后AC(指针)加1,向右写
#define   CMD_dis_gb1  0x0f             // 开显示_开光标_开光标闪烁
#define   CMD_dis_gb2  0x0e             // 开显示_开光标_关光标闪烁
#define   CMD_dis_gb3  0x0c             // 开显示_关光标_关光标闪烁
#define   CMD_OFF_dis  0x08             // 关显示_关光标_关光标闪烁
#define   CMD_set82  0x38             // 8位总线_2行显示
#define   CMD_set81  0x30             // 8位总线_1行显示(上边行)
#define   CMD_set42  0x28             // 4位总线_2行显示
#define   CMD_set41  0x20             // 4位总线_1行显示(上边行)
#define   lin_1   0x80             // 4位总线_1行显示(上边行)
#define   lin_2   0xc0             // 4位总线_1行显示(上边行)

/********************************************************************************************
// 读LCM忙程序 [底层协议] //
// LCM1602测忙,若LCM1602处于忙状态,本函数将等待至非忙状态 //
/********************************************************************************************/
void LCM1602_TestBusy(void){
    LCM1602_DB0_DB7 = 0xff;  //设备读状态
    LCM1602_RS = 0;
    LCM1602_RW = 1;
    LCM1602_E = 1;
    while(LCM1602_Busy);  //等待LCM不忙
    LCM1602_E = 0;    //
}
/********************************************************************************************
// 写指令程序 //
// 向LCM1602写命令 本函数需要1个指令集的入口参数 //
/********************************************************************************************/
void LCM1602_WriteCMD(uint8 LCM1602_command) {
   LCM1602_TestBusy();
   LCM1602_DB0_DB7 = LCM1602_command;
   LCM1602_RS = 0;
   LCM1602_RW = 0;
   LCM1602_E = 1;
   LCM1602_E = 0;
}
/********************************************************************************************
// 写数据程序 //
// 向LCM1602写数据 //
/********************************************************************************************/
void LCM1602_WriteData(uint8 LCM1602_data){
    LCM1602_TestBusy();
 LCM1602_DB0_DB7 = LCM1602_data;
   LCM1602_RS = 1;
   LCM1602_RW = 0;
   LCM1602_E = 1;
   LCM1602_E = 0;
}
/********************************************************************************************
// 打印字符串程序 //
// 向LCM发送一个字符串,长度48字符之内
// 第一行位置 0x00~0x17  第二行位置 0x40~0x57
// 应用举例:print(0x80,"doyoung.net"); //在第一行第一位处从左向右打印doyoung.net字符串
/********************************************************************************************/
void print(uint8 a,uint8 *str){
 LCM1602_WriteCMD(a | 0x80);
 while(*str != '\0'){
  LCM1602_WriteData(*str++);
 }
 *str = 0;
}
/********************************************************************************************
// 打印单字符程序 //
// 第一行位置 0x00~0x17  第二行位置 0x40~0x57
// 向LCM发送一个字符,以十六进制(0x00)表示
// 应用举例:print(0xc0,0x30); //在第二行第一位处打印字符“0”
/********************************************************************************************/
void print2(uint8 a,uint8 t){
  LCM1602_WriteCMD(a | 0x80);
  LCM1602_WriteData(t);
}
/********************************************************************************************
// LCM1602初始化 //
/********************************************************************************************/
void LCM1602_Init(void){
   LCM1602_WriteCMD(CMD_set82); //* 显示模式设置:显示2行,每个字符为5*7个像素
   LCM1602_WriteCMD(CMD_clear); //  显示清屏
   LCM1602_WriteCMD(CMD_back);  //* 数据指针指向第1行第1个字符位置
   LCM1602_WriteCMD(CMD_add1);  //  显示光标移动设置:文字不动,光标右移
   LCM1602_WriteCMD(CMD_dis_gb3);  //  显示开及光标设置:显示开,光标开,闪烁开
}
/********************************************************************************************/


/********************************************************************************************
主程序:
/********************************************************************************************/
void main()
{
   LCM1602_Init(); //LCM1602初始化
   print(0x80,"        MCU--DIY         ");
   print(0x40," www.eepw.com.cn");
   while(1){
            ;
           }
}
/********************************************************************************************/


院士
2011-12-04 12:08:47     打赏
16楼
good

专家
2011-12-05 22:05:58     打赏
17楼

         从论坛里哪位网友哪儿买来的套件中LED点阵屏与PCB上的尺寸不符,不能直接在实验板上使用,而再单购买一块点阵屏又不合算,所以只好通过一块洞洞板对其进行转接,经过一番功夫做好就成了下面见个样子:



装到DIY实验板上的样子:



LED点阵屏测试:



原程序:
#include <STC12C5A60S2.H> //STC头文件

#define LOGOSPEED 150 //设置开机LOGO部分的流动速度
#define DELAY  12 //设置每一个点显示的时间长度(1~20)

sbit led_H1 =P0 ^ 0; //设置LED点阵屏连接的I/O口
sbit led_H2 =P0 ^ 1; //设置LED点阵屏连接的I/O口
sbit led_H3 =P0 ^ 2; //设置LED点阵屏连接的I/O口
sbit led_H4 =P0 ^ 3; //设置LED点阵屏连接的I/O口
sbit led_H5 =P0 ^ 4; //设置LED点阵屏连接的I/O口
sbit led_H6 =P0 ^ 5; //设置LED点阵屏连接的I/O口
sbit led_H7 =P0 ^ 6; //设置LED点阵屏连接的I/O口
sbit led_H8 =P0 ^ 7; //设置LED点阵屏连接的I/O口

sbit led_L1 =P2 ^ 0; //设置LED点阵屏连接的I/O口
sbit led_L2 =P2 ^ 1; //设置LED点阵屏连接的I/O口
sbit led_L3 =P2 ^ 2; //设置LED点阵屏连接的I/O口
sbit led_L4 =P2 ^ 3; //设置LED点阵屏连接的I/O口
sbit led_L5 =P2 ^ 4; //设置LED点阵屏连接的I/O口
sbit led_L6 =P2 ^ 5; //设置LED点阵屏连接的I/O口
sbit led_L7 =P2 ^ 6; //设置LED点阵屏连接的I/O口
sbit led_L8 =P2 ^ 7; //设置LED点阵屏连接的I/O口

#define P0M1SET  0x00 //设置I/O口工作方式//00000000
#define P0M0SET  0xff //设置I/O口工作方式//11010011(PxM0为1时设置为强推)(左到右,高到低位)

#define P2M1SET  0x00 //设置I/O口工作方式//00000000
#define P2M0SET  0x00 //设置I/O口工作方式//01011100

idata unsigned char PWM;//显示亮度

unsigned char code logo[] =  {            // ASCII (取码:从上到下从左到右,纵向8位下高位)
 0,0,0,0,0,0,0,
 0x3C,0x40,0x3C,0x40,0x3C,0,0, // -w-
 0x3C,0x40,0x3C,0x40,0x3C,0,0, // -w-
 0x3C,0x40,0x3C,0x40,0x3C,0, // -w-
 0x00,0x60,0x60,0x00,0x00,0, // -.-
 0x38,0x54,0x54,0x54,0x08,0,0, // -e-
 0x38,0x54,0x54,0x54,0x08,0,0, // -e-
 0xFC,0x24,0x24,0x24,0x18,0,0, // -p-
 0x3C,0x40,0x3C,0x40,0x3C,0, // -w-
 0x00,0x60,0x60,0x00,0x00,0, // -.-
 0x38,0x44,0x44,0x44,0x08,0,0, // -c-
 0x38,0x44,0x44,0x44,0x38,0,0, // -o-
 0x78,0x04,0x78,0x04,0x78,0, // -m-
 0x00,0x60,0x60,0x00,0x00,0, // -.-
 0x38,0x44,0x44,0x44,0x08,0,0, // -c-
 0x04,0x78,0x04,0x04,0x78,0, // -n-
 0x00,0x00,0x00,0x00,0x00,0, // - -
 0x7F,0x02,0x0C,0x02,0x7F,0,0, // -M-
 0x3E,0x41,0x41,0x41,0x22,0,0, // -C-
 0x3F,0x40,0x40,0x40,0x3F,0,0, // -U-
 0x08,0x08,0x08,0x08,0x08,0, // ---
 0x7F,0x41,0x41,0x41,0x3E,0,0, // -D-
 0x00,0x41,0x7F,0x41,0x00,0,0, // -I-
 0x03,0x04,0x78,0x04,0x03,0, // -Y-
 0,0,0,0,0,0,0,0,0,0,
};

/*********************************************************************************************/
void delay (unsigned int a){ // 用于点扫描的延时
 unsigned int i;
 while( --a != 0){
  for(i = 0; i < DELAY; i++);
 }         
}
/*********************************************************************************************/
void delay1ms (unsigned int a){ // 1ms延时程序(12MHz 10倍于51单片机速度时)
 unsigned int i;
 while( --a != 0){
  for(i = 0; i < 600; i++);
 }         
}
/*********************************************************************************************/
void dis_off (void){
 P0 = ~P0M0SET; //关所有显示

 P2 = ~P2M0SET;


}
/*********************************************************************************************/
/*********************************************************************************************/
void displayHH1 (unsigned char d){ //第1列横向显示程序
 unsigned char i;
 i = d & 0x01;
 if(i == 0x01){
  led_H1 = 1;led_L1 = 0;delay(PWM);dis_off();}
 i = d & 0x02;
 if(i == 0x02){
  led_H2 = 1;led_L1 = 0;delay(PWM);dis_off();}
 i = d & 0x04;
 if(i == 0x04){
  led_H3 = 1;led_L1 = 0;delay(PWM);dis_off();}
 i = d & 0x08;
 if(i == 0x08){
  led_H4 = 1;led_L1 = 0;delay(PWM);dis_off();}
 i = d & 0x10;
 if(i == 0x10){
  led_H5 = 1;led_L1 = 0;delay(PWM);dis_off();}
 i = d & 0x20;
 if(i == 0x20){
  led_H6 = 1;led_L1 = 0;delay(PWM);dis_off();}
 i = d & 0x40;
 if(i == 0x40){
  led_H7 = 1;led_L1 = 0;delay(PWM);dis_off();}
 i = d & 0x80;
 if(i == 0x80){
  led_H8 = 1;led_L1 = 0;delay(PWM);dis_off();}
}
/*********************************************************************************************/
void displayHH2 (unsigned char d){ //第2列横向显示程序
 unsigned char i;
 i = d & 0x01;
 if(i == 0x01){
  led_H1 = 1;led_L2 = 0;delay(PWM);dis_off();}
 i = d & 0x02;
 if(i == 0x02){
  led_H2 = 1;led_L2 = 0;delay(PWM);dis_off();}
 i = d & 0x04;
 if(i == 0x04){
  led_H3 = 1;led_L2 = 0;delay(PWM);dis_off();}
 i = d & 0x08;
 if(i == 0x08){
  led_H4 = 1;led_L2 = 0;delay(PWM);dis_off();}
 i = d & 0x10;
 if(i == 0x10){
  led_H5 = 1;led_L2 = 0;delay(PWM);dis_off();}
 i = d & 0x20;
 if(i == 0x20){
  led_H6 = 1;led_L2 = 0;delay(PWM);dis_off();}
 i = d & 0x40;
 if(i == 0x40){
  led_H7 = 1;led_L2 = 0;delay(PWM);dis_off();}
 i = d & 0x80;
 if(i == 0x80){
  led_H8 = 1;led_L2 = 0;delay(PWM);dis_off();}

}
/*********************************************************************************************/
void displayHH3 (unsigned char d){ //第3列横向显示程序
 unsigned char i;
 i = d & 0x01;
 if(i == 0x01){
  led_H1 = 1;led_L3 = 0;delay(PWM);dis_off();}
 i = d & 0x02;
 if(i == 0x02){
  led_H2 = 1;led_L3 = 0;delay(PWM);dis_off();}
 i = d & 0x04;
 if(i == 0x04){
  led_H3 = 1;led_L3 = 0;delay(PWM);dis_off();}
 i = d & 0x08;
 if(i == 0x08){
  led_H4 = 1;led_L3 = 0;delay(PWM);dis_off();}
 i = d & 0x10;
 if(i == 0x10){
  led_H5 = 1;led_L3 = 0;delay(PWM);dis_off();}
 i = d & 0x20;
 if(i == 0x20){
  led_H6 = 1;led_L3 = 0;delay(PWM);dis_off();}
 i = d & 0x40;
 if(i == 0x40){
  led_H7 = 1;led_L3 = 0;delay(PWM);dis_off();}
 i = d & 0x80;
 if(i == 0x80){
  led_H8 = 1;led_L3 = 0;delay(PWM);dis_off();}

}
/*********************************************************************************************/
void displayHH4 (unsigned char d){ //第4列横向显示程序
 unsigned char i;
 i = d & 0x01;
 if(i == 0x01){
  led_H1 = 1;led_L4 = 0;delay(PWM);dis_off();}
 i = d & 0x02;
 if(i == 0x02){
  led_H2 = 1;led_L4 = 0;delay(PWM);dis_off();}
 i = d & 0x04;
 if(i == 0x04){
  led_H3 = 1;led_L4 = 0;delay(PWM);dis_off();}
 i = d & 0x08;
 if(i == 0x08){
  led_H4 = 1;led_L4 = 0;delay(PWM);dis_off();}
 i = d & 0x10;
 if(i == 0x10){
  led_H5 = 1;led_L4 = 0;delay(PWM);dis_off();}
 i = d & 0x20;
 if(i == 0x20){
  led_H6 = 1;led_L4 = 0;delay(PWM);dis_off();}
 i = d & 0x40;
 if(i == 0x40){
  led_H7 = 1;led_L4 = 0;delay(PWM);dis_off();}
 i = d & 0x80;
 if(i == 0x80){
  led_H8 = 1;led_L4 = 0;delay(PWM);dis_off();}
}
/*********************************************************************************************/
void displayHH5 (unsigned char d){ //第5列横向显示程序
 unsigned char i;
 i = d & 0x01;
 if(i == 0x01){
  led_H1 = 1;led_L5 = 0;delay(PWM);dis_off();}
 i = d & 0x02;
 if(i == 0x02){
  led_H2 = 1;led_L5 = 0;delay(PWM);dis_off();}
 i = d & 0x04;
 if(i == 0x04){
  led_H3 = 1;led_L5 = 0;delay(PWM);dis_off();}
 i = d & 0x08;
 if(i == 0x08){
  led_H4 = 1;led_L5 = 0;delay(PWM);dis_off();}
 i = d & 0x10;
 if(i == 0x10){
  led_H5 = 1;led_L5 = 0;delay(PWM);dis_off();}
 i = d & 0x20;
 if(i == 0x20){
  led_H6 = 1;led_L5 = 0;delay(PWM);dis_off();}
 i = d & 0x40;
 if(i == 0x40){
  led_H7 = 1;led_L5 = 0;delay(PWM);dis_off();}
 i = d & 0x80;
 if(i == 0x80){
  led_H8 = 1;led_L5 = 0;delay(PWM);dis_off();}
}
/*********************************************************************************************/
void displayHH6 (unsigned char d){ //第6列横向显示程序
 unsigned char i;
 i = d & 0x01;
 if(i == 0x01){
  led_H1 = 1;led_L6 = 0;delay(PWM);dis_off();}
 i = d & 0x02;
 if(i == 0x02){
  led_H2 = 1;led_L6 = 0;delay(PWM);dis_off();}
 i = d & 0x04;
 if(i == 0x04){
  led_H3 = 1;led_L6 = 0;delay(PWM);dis_off();}
 i = d & 0x08;
 if(i == 0x08){
  led_H4 = 1;led_L6 = 0;delay(PWM);dis_off();}
 i = d & 0x10;
 if(i == 0x10){
  led_H5 = 1;led_L6 = 0;delay(PWM);dis_off();}
 i = d & 0x20;
 if(i == 0x20){
  led_H6 = 1;led_L6 = 0;delay(PWM);dis_off();}
 i = d & 0x40;
 if(i == 0x40){
  led_H7 = 1;led_L6 = 0;delay(PWM);dis_off();}
 i = d & 0x80;
 if(i == 0x80){
  led_H8 = 1;led_L6 = 0;delay(PWM);dis_off();}
}
/*********************************************************************************************/
void displayHH7 (unsigned char d){ //第7列横向显示程序
 unsigned char i;
 i = d & 0x01;
 if(i == 0x01){
  led_H1 = 1;led_L7 = 0;delay(PWM);dis_off();}
 i = d & 0x02;
 if(i == 0x02){
  led_H2 = 1;led_L7 = 0;delay(PWM);dis_off();}
 i = d & 0x04;
 if(i == 0x04){
  led_H3 = 1;led_L7 = 0;delay(PWM);dis_off();}
 i = d & 0x08;
 if(i == 0x08){
  led_H4 = 1;led_L7 = 0;delay(PWM);dis_off();}
 i = d & 0x10;
 if(i == 0x10){
  led_H5 = 1;led_L7 = 0;delay(PWM);dis_off();}
 i = d & 0x20;
 if(i == 0x20){
  led_H6 = 1;led_L7 = 0;delay(PWM);dis_off();}
 i = d & 0x40;
 if(i == 0x40){
  led_H7 = 1;led_L7 = 0;delay(PWM);dis_off();}
 i = d & 0x80;
 if(i == 0x80){
  led_H8 = 1;led_L7 = 0;delay(PWM);dis_off();}
}
/*********************************************************************************************/
void displayHH8 (unsigned char d){ //第8列横向显示程序
 unsigned char i;
 i = d & 0x01;
 if(i == 0x01){
  led_H1 = 1;led_L8 = 0;delay(PWM);dis_off();}
 i = d & 0x02;
 if(i == 0x02){
  led_H2 = 1;led_L8 = 0;delay(PWM);dis_off();}
 i = d & 0x04;
 if(i == 0x04){
  led_H3 = 1;led_L8 = 0;delay(PWM);dis_off();}
 i = d & 0x08;
 if(i == 0x08){
  led_H4 = 1;led_L8 = 0;delay(PWM);dis_off();}
 i = d & 0x10;
 if(i == 0x10){
  led_H5 = 1;led_L8 = 0;delay(PWM);dis_off();}
 i = d & 0x20;
 if(i == 0x20){
  led_H6 = 1;led_L8 = 0;delay(PWM);dis_off();}
 i = d & 0x40;
 if(i == 0x40){
  led_H7 = 1;led_L8 = 0;delay(PWM);dis_off();}
 i = d & 0x80;
 if(i == 0x80){
  led_H8 = 1;led_L8 = 0;delay(PWM);dis_off();}
}
/*********************************************************************************************/
void diplay_data (unsigned char l,d){
  switch (l){//显示的列位置  
    case 1://   
     displayHH1(d); //将显示数据送入  
     break;//  
    case 2://   
     displayHH2(d); //将显示数据送入  
     break;//  
    case 3://   
     displayHH3(d); //将显示数据送入  
     break;//  
    case 4://   
     displayHH4(d); //将显示数据送入  
     break;//  
    case 5://   
     displayHH5(d); //将显示数据送入  
     break;//  
    case 6://  
     displayHH6(d); //将显示数据送入  
     break;//  
    case 7://   
     displayHH7(d); //将显示数据送入  
     break;//  
    case 8://  
     displayHH8(d); //将显示数据送入  
     break;//  


  }
}
/*********************************************************************************************/
/*********************************************************************************************/
void init (void){ //上电初始化
 P0M0 = P0M0SET; //设置I/O口工作方式(行为推挽,列为普通输入/输出)
 P0M1 = P0M1SET;
 P2M0 = P2M0SET;
 P2M1 = P2M1SET;
 PWM = 7;
 }
/*********************************************************************************************/

void main (void){ //主程序
 unsigned char p,a,b;
 init();
 while (1){
 
 for(p=0;p<160;p++){     //显示“www.eepw.com.cn MCU-DIY”
     for(b=0;b<LOGOSPEED;b++){
   for(a=1;a<9;a++){
    diplay_data (a,logo[a+p-1]);
   }
       }
        }
 
      
  }
 }


高工
2011-12-06 00:45:57     打赏
18楼

真不错啊


专家
2011-12-06 21:39:29     打赏
19楼

       今天测试LCM12864液晶,调试挺长时间的程序液晶始终都没有显示,正在一筹莫展的时候,发现液晶的背光突然变暗,赶紧检查开发板,发现板子上的MAX232发烫,立即关掉开发板上的电源开关,推断是USB转串口线或者是MAX232坏了,现在只能先换一条备用的USB转串口线试试,换完之后MAX232不烫了,唉!好几十块的劣质USB转串口坑爹呐!不过还好,换完USB转串口线就找出液晶不显示的原因了,原来是延时函数的事,有点粗心了。。。





测试程序:
#include <STC12C5A60S2.H> //STC头文件

/*********************************************************************************************/
/*--  调入了一幅图像:C:\Documents and Settings\地质\桌面\logo.bmp  --*/
/*--  宽度x高度=128x22  --*/
unsigned char code logo[] =                
{
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xFF,0xFF,0xFF,0xFF,0xFF,0xC7,0x81,0xE0,0x7C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xFF,0xFF,0xFF,0xFF,0xFF,0xF3,0x83,0xE0,0x7C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xFF,0xFF,0xFF,0xFF,0xFF,0xF9,0x87,0xF0,0x7C,0x03,0x00,0x80,0x80,0x00,0x00,0x00,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFC,0x87,0xF0,0xFC,0x06,0x03,0x41,0xC0,0xC0,0x00,0xC0,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFE,0x47,0xF0,0xFC,0x03,0xC0,0x40,0x41,0x40,0x22,0xE0,
0xFC,0x01,0xF0,0x00,0xF8,0x7E,0x07,0xF8,0xFC,0x07,0x00,0x81,0xE1,0x82,0xA3,0xC0,
0xFC,0x01,0xF0,0x00,0xF8,0x3F,0x0F,0xF8,0xF8,0x14,0x07,0xE2,0x40,0x27,0xF1,0x00,
0xFF,0xF9,0xF0,0x00,0xF8,0x3F,0x0F,0xF8,0xF8,0x12,0x80,0x82,0xC3,0x72,0xA3,0xE0,
0xFF,0xF9,0xFF,0xFF,0xF8,0x7F,0x0F,0xF8,0xF8,0x0B,0x80,0x82,0xC5,0x52,0x63,0x18,
0xFF,0xF9,0xFF,0xFF,0xFF,0xFE,0x5F,0xFD,0xF8,0x07,0x02,0x84,0xE3,0x61,0xF5,0x80,
0xFF,0xF9,0xFF,0xFF,0xFF,0xFE,0x5F,0x7D,0xF8,0x01,0x81,0x04,0x00,0x00,0x00,0x80,
0xFF,0xF9,0xFF,0xFF,0xFF,0xFC,0xDF,0x7D,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xFC,0x01,0xFF,0xFF,0xFF,0xF9,0xFE,0x3F,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xFC,0x01,0xF0,0x00,0xFF,0xF3,0xFE,0x3F,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xFC,0x01,0xF0,0x00,0xFF,0xC3,0xFE,0x3F,0xF0,0x00,0xE1,0xE3,0x66,0x03,0x8D,0x80,
0xFC,0x01,0xF0,0x00,0xF8,0x03,0xFE,0x3F,0xE0,0x01,0xFB,0xF3,0xFF,0x07,0xEF,0xC0,
0xFF,0xFF,0xFF,0xFF,0xF8,0x03,0xFC,0x1F,0xE0,0x03,0x03,0x33,0xBB,0x0C,0x0E,0xC0,
0xFF,0xFF,0xFF,0xFF,0xF8,0x01,0xFC,0x1F,0xE0,0x03,0x03,0x33,0x33,0x0C,0x0C,0xC0,
0xFF,0xFF,0xFF,0xFF,0xF8,0x01,0xFC,0x1F,0xE0,0x1B,0x9B,0x33,0x33,0x6E,0x6C,0xC0,
0xFF,0xFF,0xFF,0xFF,0xF8,0x00,0x70,0x07,0x80,0x19,0xF1,0xE3,0x33,0x67,0xCC,0xC0,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};
/*****************************************************************************/
/****************************************************************************/
//LCD接口定义
sbit RS =  P2^4; //模式位,为0输入指令,为1输入数据
sbit RW =  P2^5; //读写位,为0读,为1写
sbit E  =  P2^6; //使能位
#define Lcd_Bus   P0 //数据总线
sbit PSB = P2^1; //H:8位或4位并口方式,L:串口方式
sbit NC  = P2^2; //空脚
sbit RES = P2^3; //复位端,低电平有效
/*****************************************************************************/

/*********************************************************************************************/
void DELAY_MS (unsigned int a){
 unsigned int i;
 while( a-- != 0){
  for(i = 0; i < 600; i++);
 }
}
/*********************************************************************************************/

/******************************************************************************/
//LCD驱动(DY12864CBL液晶显示屏并口驱动程序)
/******************************************************************************/
void chk_busy(){//检查忙位
   RS=0;
   RW=1;
   E=1;
   Lcd_Bus=0xff;
   while((Lcd_Bus&0x80)==0x80);
   E=0;
}
/******************************************************************************/
void write_com(unsigned char cmdcode){//写命令到LCD
 chk_busy();
 RS=0;
 RW=0;
 E=1;
 Lcd_Bus=cmdcode;
 E=0;
}
/******************************************************************************/
void write_data(unsigned char Dispdata){  //写数据到LCD
 chk_busy();
 RS=1;
 RW=0;
 E=1;
 Lcd_Bus=Dispdata;
 E=0;
}
/******************************************************************************/
void lcm_init(){//初始化LCD屏)
   PSB = 1;               //H:8位或4位并口方式,L:串口方式
   NC  = 0;               //空脚
   RES = 1;               //复位端,低电平有效
   write_com(0x30);       //选择8bit数据流
   write_com(0x0c);       //开显示(无游标、不反白)
   write_com(0x01);       //清除显示,并且设定地址指针为00H
}
/*****************************************************************************/
void lcm_w_word(unsigned char *s){   //向LCM发送一个字符串,长度64字符之内。
 while(*s>0){      //
     write_data(*s);
     s++;
   }
}
/******************************************************************************/
void lcm_w_test(bit i,unsigned char word){//写指令或数据
 if(i == 0){
  write_com(word); //写指令或数据(0,指令)
 }else{
  write_data(word);//写指令或数据(1,数据)
 }
}
/******************************************************************************/
void lcm_clr(void){//清屏函数
 lcm_w_test(0,0x01); 
}
/******************************************************************************/
 /******************************************************************************
//指定显示位置// (设置LCD显示的起始位置)
/******************************************************************************/
void LCD_set_xy(  unsigned char x, //X为行(1~4)
     unsigned char y ){ //Y为列(0~7)
    unsigned char address;
 switch(x){
  case 0: address = 0x80 + y; break;   
     case 1: address = 0x80 + y; break;
  case 2: address = 0x90 + y; break;
      case 3: address = 0x88 + y; break;
  case 4: address = 0x98 + y; break;
  default:address = 0x80 + y; break;
 }
    lcm_w_test(0, address);
}
/******************************************************************************
//图形方式12864显示字模(横向8位左高位取模)
/******************************************************************************/
void Disp_img(unsigned char  *img){ 
 unsigned char i,j;
 unsigned int k = 0;
 lcm_w_test(0,0x36); //图形方式
 for(i=0;i<32;i++){
  lcm_w_test(0,0x80+i);
  lcm_w_test(0,0x80);
     for(j=0;j<16;j++) {
   lcm_w_test(1,img[k++]);
  }
   }
  for(i=0;i<32;i++){
  lcm_w_test(0,0x80+i);
  lcm_w_test(0,0x88);
     for(j=0;j<16;j++) {
   lcm_w_test(1,img[k++]);
    }
 }

/*****************************************************************************/
//---主程序---//
/*****************************************************************************/
main() {
 lcm_init();    //初始化液晶显示器
    Disp_img(logo);//显示图片测试内容
 DELAY_MS (10000);      
 lcm_clr();
  while(1){//主循环
 lcm_init();    //初始化液晶显示器
    LCD_set_xy(1,0); //写入字符的位置
 lcm_w_word("预祝电子产品世界"); //写入字符内容
 LCD_set_xy(2,0);
 lcm_w_word("  MCU--DIY活动  ");
 LCD_set_xy(3,0);
 lcm_w_word("  取得圆满成功  ");
 LCD_set_xy(4,0);
 lcm_w_word(" www.eepw.com.cn");
 DELAY_MS (30000);     
  
      }


助工
2011-12-06 22:43:36     打赏
20楼

太嗨了……


共53条 2/6 1 2 3 4 5 6 ›| 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]