|
部分代碼 可自行下載壓縮包 全部代碼 測試可用
#include <reg51.h>
#include <intrins.h>
#include "tlc2543.h"
#include "led_display.h"
#define L 0 //Low level;
#define H 1 //High level;
#define uint8 unsigned char
#define uint16 unsigned int
#define int8 char
#define int16 int
bit flag=0;
uint8 aa[5],*ap;
void aa1 (void) interrupt 1
{
TH0=0x3c;
TL0=0xb0;
flag=0;
}
void initial (void)
{
TCON=(TCON&0xfe)|0x00 ;//interrupt mode control;
IE=(IE&0x7d)|0x82;//interrupt enable ;
IP=(IP&0xfe)|0x02;//interrupt priority;
TMOD=(TMOD&0xf0)|0x01;//timer counter mode;
TH0=0x3c;
TL0=0xb0;
TCON=(TCON&0xaf)|0x10;//timer control register;
CE_TLC2543 =0;
}
main(void)
{
uint8 i;
uint16 b;
initial();
START_TLC2543 ( 0x00 ) ;
while( 1 )
{
if(EOC_TLC2543)
{
b=READ_TLC2543 ( 0 );
for( i = 0 ; i<4 ; i++ )
{
aa[i]=b%10;
b/=10;
}
//flag=1;
}
Dynamic_Display ( 4 , aa );
}
}
#include "nokia5110.h"
#include "english_6x8_pixel.h"
#include "write_chinese_string_pixel.h"
/*-----------------------------------------------------------------------
LCD_init : 3310LCD初始化
編寫日期 :2004-8-10
最后修改日期 :2004-8-10
-----------------------------------------------------------------------*/
void delay_1us(void) //1us延時函數
{
unsigned int i;
for(i=0;i<1000;i++);
}
void delay_1ms(void) //1ms延時函數
{
unsigned int i;
for (i=0;i<1140;i++);
}
void delay_nms(unsigned int n) //N ms延時函數
{
unsigned int i=0;
for (i=0;i<n;i++)
delay_1ms();
}
void LCD_init(void)
{
// 產生一個讓LCD復位的低電平脈沖
LCD_RST = 0;
delay_1us();
LCD_RST = 1;
// 關閉LCD
LCD_CE = 0;
delay_1us();
// 使能LCD
LCD_CE = 1;
delay_1us();
LCD_write_byte(0x21, 0); // 使用擴展命令設置LCD模式
LCD_write_byte(0xc8, 0); // 設置偏置電壓
LCD_write_byte(0x06, 0); // 溫度校正
LCD_write_byte(0x13, 0); // 1:48
LCD_write_byte(0x20, 0); // 使用基本命令
LCD_clear(); // 清屏
LCD_write_byte(0x0c, 0); // 設定顯示模式,正常顯示
// 關閉LCD
LCD_CE = 0;
}
/*-----------------------------------------------------------------------
LCD_clear : LCD清屏函數
編寫日期 :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 : 設置LCD坐標函數
輸入參數: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 : 顯示英文字符
輸入參數: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);
}
/*-----------------------------------------------------------------------
LCD_write_english_String : 英文字符串顯示函數
輸入參數:*s :英文字符串指針;
X、Y : 顯示字符串的位置,x 0-83 ,y 0-5
編寫日期 :2004-8-10
最后修改日期 :2004-8-10
-----------------------------------------------------------------------*/
void LCD_write_english_string(unsigned char X,unsigned char Y,char *s)
{
LCD_set_XY(X,Y);
while (*s)
{
LCD_write_char(*s);
s++;
}
}
/*---------------------------------------------
LCD_write_byte : 使用SPI接口寫數據到LCD
輸入參數:data :寫入的數據;
command :寫數據/命令選擇;
編寫日期 :2004-8-10
最后修改日期 :2004-8-13
-----------------------------------------------*/
void LCD_write_letter(unsigned char row, unsigned char line,unsigned char c) //row:? line:? dd:??
{
unsigned char i;
LCD_set_XY(row, line);
for(i=0; i<6;i++)
{
LCD_write_byte(font1[c][i],1);
}
}
/*-----------------------------------------------------------------------
LCD_write_chinese_string: 在LCD上顯示漢字
輸入參數:X、Y :顯示漢字的起始X、Y坐標;
ch_with :漢字點陣的寬度
num :顯示漢字的個數;
line :漢字點陣數組中的起始行數
row :漢字顯示的行間距
編寫日期 :2004-8-11
最后修改日期 :2004-8-12
測試:
LCD_write_chi(0,0,12,7,0,0);
LCD_write_chi(0,2,12,7,0,0);
LCD_write_chi(0,4,12,7,0,0);
-----------------------------------------------------------------------*/
void LCD_write_chinese_string(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); //??????
for (i=0;i<num;)
{
for (n=0; n<ch_with*2; 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(write_chinese[line+i][n],1);
}
i++;
LCD_set_XY((X+(ch_with+row)*i),Y);
}
}
/*-----------------------------------------------------------------------
LCD_draw_map : 位圖繪制函數
輸入參數:X、Y :位圖繪制的起始X、Y坐標;
*map :位圖點陣數據;
Pix_x :位圖像素(長)
Pix_y :位圖像素(寬)
編寫日期 :2004-8-13
最后修改日期 :2004-8-13
-----------------------------------------------------------------------*/
void LCD_draw_bmp_pixel(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; //????????
else
row=Pix_y/8+1;
for (n=0;n<row;n++)
{
LCD_set_XY(X,Y);
for(i=0; i<Pix_x; i++)
{
LCD_write_byte(map[i+n*Pix_x], 1);
}
Y++; //??
}
}
/*-----------------------------------------------------------------------
LCD_write_byte : 使用SPI接口寫數據到LCD
輸入參數:data :寫入的數據;
command :寫數據/命令選擇;
編寫日期 :2004-8-10
最后修改日期 :2004-8-13
-----------------------------------------------------------------------*/
void LCD_write_byte(unsigned char dat, unsigned char command)
{
unsigned char i;
LCD_CE = 0;
if (command == 0)
LCD_DC = 0;
else
LCD_DC = 1;
for(i=0;i<8;i++)
{
if(dat&0x80)
SDIN = 1;
else
SDIN = 0;
SCLK = 0;
dat = dat << 1;
SCLK = 1;
}
LCD_CE = 1;
}
#include "reg51.h"
#include "nokia5110.h"
#include "tlc2543.h"
//***********************************
#define delay_time 25767
#define unit unsigned int
#define uchar unsigned char
uchar h,g;
uint8 aa[5],*ap;
/********************************************************************/
/******************************************************************************/
void main(void)
{
uint8 i;
uint16 b;
CE_TLC2543 =0;
START_TLC2543 ( 1 ) ; //通道1開始轉換
LCD_init();
LCD_clear();
while( 1 )
{
LCD_write_chinese_string(1,1,12,5,0,3);
LCD_write_english_string(0,3,"Z:");
LCD_write_english_string(0,4,"Y:");
LCD_write_english_string(0,5,"X:");
if(EOC_TLC2543)
{
b=READ_TLC2543 ( 1 ); //讀通道1的值
for( i = 0 ; i<4 ; i++ )
{
aa[i]=b%10;
LCD_write_letter(54-6*i,3,aa[i]);
b/=10;
g++ ;
g=0;
}
if(g==1){START_TLC2543 ( 2 ) ; } //通道2開始轉換
if(EOC_TLC2543)
{
b=READ_TLC2543 ( 2 ); //讀通道2
for( i = 0 ; i<4 ; i++ )
{
aa[i]=b%10;
LCD_write_letter(54-6*i,4,aa[i]);
b/=10;
h++;
h=0;
}
if(h==1){START_TLC2543 ( 3 ) ; }
if(EOC_TLC2543)
{
b=READ_TLC2543 ( 3 );
for( i = 0 ; i<4 ; i++ )
{
aa[i]=b%10;
LCD_write_letter(54-6*i,5,aa[i]);
b/=10;
}
}
}
}
}
}
|
評分
-
查看全部評分
|