?? ht1621.c
字號:
/******************************************************************
編制時間:2006.10.28
編制人:梁香勇
編制目的:測試筆段型模塊
程序應用功能:現(xiàn)在能應用與ES019004/ES02500,可用于ES025004G的按鈕測試4
應用IC:HT162
*******************************************************************/
#include <AT89X51.h>
#include <Intrins.h>
#define CS P3_2 // Chip Selection (Low Effective)
#define SDA P3_0 // Data I/O
#define SCK P3_1 // Write Clock Input (0 to 1)(4us Tclk is needed)
sbit K2switch = P3^3;
sbit K1switch = P3^4;
#define seg 32
void delay4us(void); // Delay 4us
void UsTime(unsigned char i);
void SetMode(unsigned char ICMode);
void delay100ms(void);
void delay500ms(void);
void delay1s(void); // Delay 1 second
void display(unsigned char *pdbbit);
code unsigned char wcd1[]={ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff };
code unsigned char wcd2[]={ 0x00,0x07,0x0f,0x07,0x07,0x00,0x00,0x00,0x00,0x00,0x0e,0x0e,0x0f,0x0e,0x0f,0x0e,0x0f,0x0e,0x0f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0f,0x07,0x0f,0x07,0x00,0x0f,0x00 };
code unsigned char wcd3[]={ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 };
code unsigned char wcd4[]={ 0x0e,0x0e,0x0e,0x0e,0x0e,0x0e,0x0e,0x0e,0x0e,0x0e,0x0e,0x0e,0x0e,0x0e,0x0e,0x0e,0x0e,0x0e,0x0e,0x0e,0x0e,0x0e,0x0e,0x0e,0x0e,0x0e,0x0e,0x0e,0x0e,0x0e,0x0e,0x0e };
//==================================================
//延時微秒
//==================================================
void Delay_us(unsigned char us)
{
unsigned char j;
for(j=0;j<us;j++)
_nop_();
}
// Delay microsecond larger than 400us
void DelayUs(unsigned int Tus)
{
Tus = Tus - 135;
Tus = (Tus - 9)/11;
while (--Tus >0);
}
void delay4us(void)
{
// 4us delay
}
// Delay microsecond less than 255us
void UsTime(unsigned char i)
{
i=i/2-5;
while(--i!=0);
}
void delay100ms(void)
{
unsigned char i;
for (i = 0 ; i < 2 ; i++)
{
DelayUs(25000);
}
}
void delay500ms(void)
{
unsigned char i;
for (i = 0 ; i < 10 ; i++)
{
DelayUs(50000);
}
}
void delay1s(void)
{
unsigned char i;
for (i = 0 ; i < 20 ; i++)
{
DelayUs(50000);
}
}
void SetCA(unsigned char Addr)
{
unsigned char i;
SetMode(0xA0);
for (i = 0; i < 6; i++)
{
SCK = 0;
SDA = (Addr << (i + 2)) & 0x80;
SCK = 1;
}
}
void SetMode(unsigned char ICMode)
{
unsigned char i;
CS = 0;
CS = 1;
delay4us();
CS = 0;
for (i = 0; i < 3; i++)
{
SCK = 0;
SDA = (ICMode << i) & 0x80;
SCK = 1;
}
}
// Send a command to the IC
void SendCmd(unsigned char Command)
{
// 9 bits total
unsigned char i;
for (i = 0; i < 9; i++)
{
SCK = 0;
SDA = (Command << i) & 0x80;
SCK = 1;
}
}
void WriteData(unsigned char dByte)
{
unsigned char i;
for (i = 0; i < 4; i++)
{ if(K1switch==1)
{
if(K1switch==1)
{Delay_us(5);
for(;;)
{ if(K2switch==1)
{ Delay_us(5);
if(K2switch==1)
return;
}
}
}
// Delay_1s();
// Delay_1s();
// Delay_1s();
// Delay_1s();
}
else
{
SCK = 0;
SDA = (dByte >> i) & 0x01;
SCK = 1;
}
}
}
//***********************************************
//普通掃描
//**********************************************
void display(unsigned char *pdbbit)
{
unsigned char m;
SetCA(0);
for(m=0; m < seg; m++)
{
WriteData(pdbbit[m]);
delay100ms();
//delay100ms();
}
}
//***********************************************
//快速掃描
//**********************************************
void displayL(unsigned char *pdbbit)
{
unsigned char m;
SetCA(0);
for(m=0; m < seg; m++)
{
WriteData(pdbbit[m]);
//delay100ms();
//delay100ms();
}
}
//clear all display
void clear(void)
{
unsigned char n;
SetCA(0);
for(n=0; n < seg; n++)
{
WriteData(0x00);
}
}
// LCD Initialization
void LCD_Init(void)
{
SetMode(0x80);
SendCmd(0x01);
SendCmd(0x18);
SendCmd(0x29);
SendCmd(0x03);
}
void main(void)
{
//P3=0;
K2switch=0;
K1switch=0;
LCD_Init();
clear();
while(1)
{
displayL(wcd1);
delay500ms();
delay500ms();
display(wcd3);
delay500ms();
// display(wcd1);
// delay500ms();
// delay500ms();
displayL(wcd1);
delay500ms();
delay500ms();
display(wcd3);
delay500ms();
// delay500ms();
// display(wcd1);
// delay500ms();
// display(wcd3);
// delay500ms();
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -