由于1S的測量閘門時間在業(yè)余條件下不好測試,因此,實驗程序中在LCD上同時顯示實時時鐘用于判斷1S閘門時間的準確性。實驗中,我使用CDMA手機上顯示的GPS衛(wèi)星精確時間進行比較。手機時間顯示的最小單位是分鐘,測量時一旦手機分鐘值發(fā)生跳變,則立即記錄下LCD顯示的秒值,這樣的話讓頻率計運行一段時間后,再多次記錄下LCD顯示的秒,就可以準確判斷頻率計的異步時鐘是否準確。實驗過程中,我讓頻率計走了10個小數(shù)左右,測量的1S時鐘還是非常準確的。
#include
#include
#include lcd.h
#include 6x8.h
#include chinese.h
/*-----------------------------------------------------------------------
LCD_init : 3310LCD初始化
編寫日期 :2004-8-10
最后修改日期 :2004-8-10
-----------------------------------------------------------------------*/
void LCD_init(void)
{
PORTB &= ~LCD_RST; // 產(chǎn)生一個讓LCD復(fù)位的低電平脈沖
delay_1us();
PORTB |= LCD_RST;
PORTB &= ~LCD_CE ; // 關(guān)閉LCD
delay_1us();
PORTB |= LCD_CE; // 使能LCD
delay_1us();
LCD_write_byte(0x21, 0); // 使用擴展命令設(shè)置LCD模式
LCD_write_byte(0xc8, 0); // 設(shè)置偏置電壓
LCD_write_byte(0x06, 0); // 溫度校正
LCD_write_byte(0x13, 0); // 1:48
LCD_write_byte(0x20, 0); // 使用基本命令
LCD_clear(); // 清屏
LCD_write_byte(0x0c, 0); // 設(shè)定顯示模式,正常顯示
PORTB &= ~LCD_CE ; // 關(guān)閉LCD
//LCD_clear();
}
/*-----------------------------------------------------------------------
LCD_clear : LCD清屏函數(shù)
編寫日期 :2004-8-10
最后修改日期 :2004-8-10
-----------------------------------------------------------------------*/
void LCD_clear(void)
{
unsigned int i;
LCD_write_byte(0x0c, 0);
LCD_write_byte(0x80, 0);
for (i=0; i<504; i++)
LCD_write_byte(0, 1);
}
/*-----------------------------------------------------------------------
LCD_set_XY : 設(shè)置LCD坐標函數(shù)
輸入?yún)?shù):X :0-83
Y :0-5
編寫日期 :2004-8-10
最后修改日期 :2004-8-10
-----------------------------------------------------------------------*/
void LCD_set_XY(unsigned char X, unsigned char Y)
{
LCD_write_byte(0x40 | Y, 0); // column
LCD_write_byte(0x80 | X, 0); // row
}
/*-----------------------------------------------------------------------
LCD_write_char : 顯示英文字符
輸入?yún)?shù):c :顯示的字符;
編寫日期 :2004-8-10
最后修改日期 :2004-8-10
-----------------------------------------------------------------------*/
void LCD_write_char(unsigned char c)
{
unsigned char line;
//c -= 32;
//for (line=0; line<6; line++)
//LCD_write_byte(font6x8[c][line], 1);
for (line=0; line<7; line++)
LCD_write_byte(font7x13[c][line], 1);
for (line=7; line<14; line++)
LCD_write_byte(font7x13[c][line], 1);
}
/*-----------------------------------------------------------------------
LCD_write_char : 英文字符串顯示函數(shù)
輸入?yún)?shù):*s :英文字符串指針;
X、Y : 顯示字符串的位置
編寫日期 :2004-8-10
最后修改日期 :2004-8-10
-----------------------------------------------------------------------*/
void LCD_write_String(unsigned char X,unsigned char Y,char *s)
{
unsigned char line;
unsigned char i=0;
while (*s)
{
LCD_set_XY(X+i*7,Y);
for (line=0; line<7; line++)
LCD_write_byte(font7x13[*s-0X30][line], 1);
LCD_set_XY(X+i*7,Y+1);
for (line=7; line<14; line++)
LCD_write_byte(font7x13[*s-0X30][line], 1);
s++;
i++;
}
}
/*-----------------------------------------------------------------------
LCD_write_chi: 在LCD上顯示漢字
輸入?yún)?shù):X、Y :顯示漢字的起始X、Y坐標;
ch_with :漢字點陣的寬度
num :顯示漢字的個數(shù);
line :漢字點陣數(shù)組中的起始行數(shù)
row :漢字顯示的行間距
編寫日期 :2004-8-11
最后修改日期 :2004-8-12
-----------------------------------------------------------------------*/
void LCD_write_chi(unsigned char X, unsigned char Y,
unsigned char ch_with,unsigned char num,
unsigned char line,unsigned char row)
{
unsigned char i,n;
LCD_set_XY(X,Y); //設(shè)置初始位置
for (i=0;i{
for (n=0; n{
if (n==ch_with) //寫漢字的下半部分
{
if (i==0) LCD_set_XY(X,Y+1);
else
LCD_set_XY((X+(ch_with+row)*i),Y+1);
}
LCD_write_byte(china_char[line+i][n],1);
}
i++;
LCD_set_XY((X+(ch_with+row)*i),Y);
}
}
/*-----------------------------------------------------------------------
LCD_write_chi: 漢字移動
輸入?yún)?shù):X、Y :顯示漢字的起始X、Y坐標;
T :移動速度;
編寫日期 :2004-8-13
最后修改日期 :2004-8-13
-----------------------------------------------------------------------*/
void LCD_MOVe_chi (unsigned char X, unsigned char Y, unsigned char T)
{
unsigned char i,n,j=0;
unsigned char buffer_h[84]={0};
unsigned char buffer_l[84]={0};
for (i=0; i<156; i++)
{
buffer_h[83] = china_char[i/12][j];
buffer_l[83] = china_char[i/12][j+12];
j++;
if (j==12) j=0;
for (n=0; n<83; n++)
{
buffer_h[n]=buffer_h[n+1];
buffer_l[n]=buffer_l[n+1];
}
LCD_set_XY(X,Y);
for (n=0; n<83; n++)
{
LCD_write_byte(buffer_h[n],1);
}
LCD_set_XY(X,Y+1);
for (n=0; n<83; n++)
{
LCD_write_byte(buffer_l[n],1);
}
delay_nms(T);
}
}
/*-----------------------------------------------------------------------
LCD_draw_map : 位圖繪制函數(shù)
輸入?yún)?shù):X、Y :位圖繪制的起始X、Y坐標;
*map :位圖點陣數(shù)據(jù);
Pix_x :位圖像素(長)
Pix_y :位圖像素(寬)
編寫日期 :2004-8-13
最后修改日期 :2004-8-13
-----------------------------------------------------------------------*/
void LCD_draw_map(unsigned char X,unsigned char Y,unsigned char *map,
unsigned char Pix_x,unsigned char Pix_y)
{
unsigned int i,n;
unsigned char row;
if (Pix_y%8==0) row=Pix_y/8; //計算位圖所占行數(shù)
else
row=Pix_y/8+1;
for (n=0;n
{
LCD_set_XY(X,Y);
for(i=0; i{
LCD_write_byte(map[i+n*Pix_x], 1);
}
Y++; //換行
}
}
/*-----------------------------------------------------------------------
LCD_write_byte : 使用SPI接口寫數(shù)據(jù)到LCD
輸入?yún)?shù):data :寫入的數(shù)據(jù);
command :寫數(shù)據(jù)/命令選擇;
編寫日期 :2004-8-10
最后修改日期 :2004-8-13
-----------------------------------------------------------------------*/
void LCD_write_byte(unsigned char data, unsigned char command)
{
PORTB &= ~LCD_CE ; // 使能LCD
if (command == 0)
PORTB &= ~LCD_DC ; // 傳送命令
else
PORTB |= LCD_DC ; // 傳送數(shù)據(jù)
SPDR = data; // 傳送數(shù)據(jù)到SPI寄存器
while ((SPSR & 0x80) == 0); // 等待數(shù)據(jù)傳送完畢
PORTB |= LCD_CE ; // 關(guān)閉LCD
}