|
AD7705程序
- #include<reg52.h> //頭文件
- #include<intrins.h>//頭文件
- #define uint unsigned int //宏定義
- #define uchar unsigned char//宏定義
- #define datlcd P0
- sbit lcdrs = P2^0; //液晶讀
- sbit lcdrw = P2^1; //液晶寫
- sbit lcden = P2^2;//液晶選擇
- #define SOFT_SPI /* 定義此行表示使用GPIO模擬SPI接口 */
- //#define HARD_SPI /* 定義此行表示使用CPU的硬件SPI接口 */
- /* 通道1和通道2的增益,輸入緩沖,極性 */
- #define __CH1_GAIN_BIPOLAR_BUF (GAIN_1 | UNIPOLAR | BUF_EN)
- #define __CH2_GAIN_BIPOLAR_BUF (GAIN_1 | UNIPOLAR | BUF_EN)
- /*
- 接線方法: STC89C52開發(fā)板,請使用杜邦線連接。
- TM7705模塊 STC89C52開發(fā)板
- VCC ------ 5.0V (3.3V)
- GND ------ GND
- CS ------ P1.0
- RST ------ P1.1
- DIN ------ P1.2
- SCK ------ P1.3
- DOUT ------ P1.4
- DRDY ------ P1.5
- */
- #if !defined(SOFT_SPI) && !defined(HARD_SPI)
- #error "Please define SPI Interface mode : SOFT_SPI or HARD_SPI"
- #endif
- #ifdef SOFT_SPI /* 軟件SPI */
- /* 定義GPIO端口 */
- sbit CS = P1^0;
- sbit RESET = P1^1;
- sbit DIN = P1^2;
- sbit SCK = P1^3;
- sbit DOUT = P1^4;
- sbit DRDY = P1^5;
- /* 定義口線置0和置1的宏 */
- #define CS_0() CS = 0
- #define CS_1() CS = 1
- #define RESET_0() RESET = 0
- #define RESET_1() RESET = 1
- #define DI_0() DIN = 0
- #define DI_1() DIN = 1
- #define SCK_0() SCK = 0
- #define SCK_1() SCK = 1
- #define DO_IS_HIGH() (DOUT != 0)
- #define DRDY_IS_LOW() (DRDY == 0)
- #endif
- #ifdef HARD_SPI /* 硬件SPI */
- #error "Don't surport Hard SPI Interface mode"
- #endif
- /* 通信寄存器bit定義 */
- enum
- {
- /* 寄存器選擇 RS2 RS1 RS0 */
- REG_COMM = 0x00, /* 通信寄存器 */
- REG_SETUP = 0x10, /* 設(shè)置寄存器 */
- REG_CLOCK = 0x20, /* 時鐘寄存器 */
- REG_DATA = 0x30, /* 數(shù)據(jù)寄存器 */
- REG_ZERO_CH1 = 0x60, /* CH1 偏移寄存器 */
- REG_FULL_CH1 = 0x70, /* CH1 滿量程寄存器 */
- REG_ZERO_CH2 = 0x61, /* CH2 偏移寄存器 */
- REG_FULL_CH2 = 0x71, /* CH2 滿量程寄存器 */
- /* 讀寫操作 */
- WRITE = 0x00, /* 寫操作 */
- READ = 0x08, /* 讀操作 */
- /* 通道 */
- CH_1 = 0, /* AIN1+ AIN1- */
- CH_2 = 1, /* AIN2+ AIN2- */
- CH_3 = 2, /* AIN1- AIN1- */
- CH_4 = 3 /* AIN1- AIN2- */
- };
- /* 設(shè)置寄存器bit定義 */
- enum
- {
- MD_NORMAL = (0 << 6), /* 正常模式 */
- MD_CAL_SELF = (1 << 6), /* 自校準(zhǔn)模式 */
- MD_CAL_ZERO = (2 << 6), /* 校準(zhǔn)0刻度模式 */
- MD_CAL_FULL = (3 << 6), /* 校準(zhǔn)滿刻度模式 */
- GAIN_1 = (0 << 3), /* 增益 */
- GAIN_2 = (1 << 3), /* 增益 */
- GAIN_4 = (2 << 3), /* 增益 */
- GAIN_8 = (3 << 3), /* 增益 */
- GAIN_16 = (4 << 3), /* 增益 */
- GAIN_32 = (5 << 3), /* 增益 */
- GAIN_64 = (6 << 3), /* 增益 */
- GAIN_128 = (7 << 3), /* 增益 */
- /* 無論雙極性還是單極性都不改變?nèi)魏屋斎胄盘柕臓顟B(tài),它只改變輸出數(shù)據(jù)的代碼和轉(zhuǎn)換函數(shù)上的校準(zhǔn)點 */
- BIPOLAR = (0 << 2), /* 雙極性輸入 */
- UNIPOLAR = (1 << 2), /* 單極性輸入 */
- BUF_NO = (0 << 1), /* 輸入無緩沖(內(nèi)部緩沖器不啟用) */
- BUF_EN = (1 << 1), /* 輸入有緩沖 (啟用內(nèi)部緩沖器) */
- FSYNC_0 = 0,
- FSYNC_1 = 1 /* 不啟用 */
- };
- /* 時鐘寄存器bit定義 */
- enum
- {
- CLKDIS_0 = 0x00, /* 時鐘輸出使能 (當(dāng)外接晶振時,必須使能才能振蕩) */
- CLKDIS_1 = 0x10, /* 時鐘禁止 (當(dāng)外部提供時鐘時,設(shè)置該位可以禁止MCK_OUT引腳輸出時鐘以省電 */
- /*
- 2.4576MHz(CLKDIV=0 )或為 4.9152MHz (CLKDIV=1 ),CLK 應(yīng)置 "0"。
- 1MHz (CLKDIV=0 )或 2MHz (CLKDIV=1 ),CLK 該位應(yīng)置 "1"
- */
- CLK_4_9152M = 0x08,
- CLK_2_4576M = 0x00,
- CLK_1M = 0x04,
- CLK_2M = 0x0C,
- FS_50HZ = 0x00,
- FS_60HZ = 0x01,
- FS_250HZ = 0x02,
- FS_500HZ = 0x04,
- /*
- 四十九、電子秤應(yīng)用中提高TM7705 精度的方法
- 當(dāng)使用主時鐘為 2.4576MHz 時,強烈建議將時鐘寄存器設(shè)為 84H,此時數(shù)據(jù)輸出更新率為10Hz,即每0.1S 輸出一個新數(shù)據(jù)。
- 當(dāng)使用主時鐘為 1MHz 時,強烈建議將時鐘寄存器設(shè)為80H, 此時數(shù)據(jù)輸出更新率為4Hz, 即每0.25S 輸出一個新數(shù)據(jù)
- */
- ZERO_0 = 0x00,
- ZERO_1 = 0x80
- };
- static void TM7705_SyncSPI(void);
- static void TM7705_Send8Bit(uint8_t _data);
- static uint8_t TM7705_Recive8Bit(void);
- static void TM7705_WriteByte(uint8_t _data);
- static void TM7705_Write3Byte(uint32_t _data);
- static uint8_t TM7705_ReadByte(void);
- static uint16_t TM7705_Read2Byte(void);
- static uint32_t TM7705_Read3Byte(void);
- static void TM7705_WaitDRDY(void);
- static void TM7705_ResetHard(void);
- static void TM7705_Delay(void);
- /*
- *********************************************************************************************************
- * 函 數(shù) 名: bsp_InitTM7705
- * 功能說明: 配置STM32的GPIO和SPI接口,用于連接 TM7705
- * 形 參: 無
- * 返 回 值: 無
- *********************************************************************************************************
- */
- void bsp_InitTM7705(void)
- {
- #ifdef SOFT_SPI /* 軟件SPI */
- /* 配置REST口線為推挽輸出,缺省輸出高電平 */
- /* 配置CS口線為推挽輸出,缺省輸出高電平 */
- /* 配置SCK口線為推挽輸出,缺省輸出高電平 */
- /* 配置DIN口線為推挽輸出,缺省輸出高電平 */
- /* 配置DOUT口線為輸入浮空模式 */
- /* 配置DOUT口線為輸入上拉模式 */
- #endif
- bsp_DelayMS(10);
- TM7705_ResetHard(); /* 硬件復(fù)位 */
- /*
- 在接口序列丟失的情況下,如果在DIN 高電平的寫操作持續(xù)了足夠長的時間(至少 32個串行時鐘周期),
- TM7705 將會回到默認狀態(tài)。
- */
- bsp_DelayMS(5);
- TM7705_SyncSPI(); /* 同步SPI接口時序 */
- bsp_DelayMS(5);
- /* 配置時鐘寄存器 */
- TM7705_WriteByte(REG_CLOCK | WRITE | CH_1); /* 先寫通信寄存器,下一步是寫時鐘寄存器 */
- TM7705_WriteByte(CLKDIS_0 | CLK_4_9152M | FS_50HZ); /* 刷新速率50Hz */
- //TM7705_WriteByte(CLKDIS_0 | CLK_4_9152M | FS_500HZ); /* 刷新速率500Hz */
- /* 每次上電進行一次自校準(zhǔn) */
- TM7705_CalibSelf(1); /* 內(nèi)部自校準(zhǔn) CH1 */
- bsp_DelayMS(5);
- }
- /*
- *********************************************************************************************************
- * 函 數(shù) 名: TM7705_Delay
- * 功能說明: CLK之間的延遲,時序延遲. 對于51,可以不延遲
- * 形 參: 無
- * 返 回 值: 無
- *********************************************************************************************************
- */
- static void TM7705_Delay(void)
- {
- //uint16_t i;
- //for (i = 0; i < 5; i++);
- }
- /*
- *********************************************************************************************************
- * 函 數(shù) 名: TM7705_ResetHard
- * 功能說明: 硬件復(fù)位 TM7705芯片
- * 形 參: 無
- * 返 回 值: 無
- *********************************************************************************************************
- */
- static void TM7705_ResetHard(void)
- {
- RESET_1();
- bsp_DelayMS(1);
- RESET_0();
- bsp_DelayMS(2);
- RESET_1();
- bsp_DelayMS(1);
- }
- /*
- *********************************************************************************************************
- * 函 數(shù) 名: TM7705_SyncSPI
- * 功能說明: 同步TM7705芯片SPI接口時序
- * 形 參: 無
- * 返 回 值: 無
- *********************************************************************************************************
- */
- static void TM7705_SyncSPI(void)
- {
- /* AD7705串行接口失步后將其復(fù)位。復(fù)位后要延時500us再訪問 */
- CS_0();
- TM7705_Send8Bit(0xFF);
- TM7705_Send8Bit(0xFF);
- TM7705_Send8Bit(0xFF);
- TM7705_Send8Bit(0xFF);
- CS_1();
- }
- /*
- *********************************************************************************************************
- * 函 數(shù) 名: TM7705_Send8Bit
- * 功能說明: 向SPI總線發(fā)送8個bit數(shù)據(jù)。 不帶CS控制。
- * 形 參: _data : 數(shù)據(jù)
- * 返 回 值: 無
- *********************************************************************************************************
- */
- static void TM7705_Send8Bit(uint8_t _data)
- {
- uint8_t i;
- for(i = 0; i < 8; i++)
- {
- if (_data & 0x80)
- {
- DI_1();
- }
- else
- {
- DI_0();
- }
- SCK_0();
- _data <<= 1;
- TM7705_Delay();
- SCK_1();
- TM7705_Delay();
- }
- }
- /*
- *********************************************************************************************************
- * 函 數(shù) 名: TM7705_Recive8Bit
- * 功能說明: 從SPI總線接收8個bit數(shù)據(jù)。 不帶CS控制。
- * 形 參: 無
- * 返 回 值: 無
- *********************************************************************************************************
- */
- static uint8_t TM7705_Recive8Bit(void)
- {
- uint8_t i;
- uint8_t read = 0;
- for (i = 0; i < 8; i++)
- {
- SCK_0();
- TM7705_Delay();
- read = read<<1;
- if (DO_IS_HIGH())
- {
- read++;
- }
- SCK_1();
- TM7705_Delay();
- }
- return read;
- }
- /*
- *********************************************************************************************************
- * 函 數(shù) 名: TM7705_WriteByte
- * 功能說明: 寫入1個字節(jié)。帶CS控制
- * 形 參: _data :將要寫入的數(shù)據(jù)
- * 返 回 值: 無
- *********************************************************************************************************
- */
- static void TM7705_WriteByte(uint8_t _data)
- {
- CS_0();
- TM7705_Send8Bit(_data);
- CS_1();
- }
- /*
- *********************************************************************************************************
- * 函 數(shù) 名: TM7705_Write3Byte
- * 功能說明: 寫入3個字節(jié)。帶CS控制
- * 形 參: _data :將要寫入的數(shù)據(jù)
- * 返 回 值: 無
- *********************************************************************************************************
- */
- static void TM7705_Write3Byte(uint32_t _data)
- {
- CS_0();
- TM7705_Send8Bit((_data >> 16) & 0xFF);
- TM7705_Send8Bit((_data >> 8) & 0xFF);
- TM7705_Send8Bit(_data);
- CS_1();
- }
- /*
- *********************************************************************************************************
- * 函 數(shù) 名: TM7705_ReadByte
- * 功能說明: 從AD芯片讀取一個字(16位)
- * 形 參: 無
- * 返 回 值: 讀取的字(16位)
- *********************************************************************************************************
- */
- static uint8_t TM7705_ReadByte(void)
- {
- uint8_t read;
- CS_0();
- read = TM7705_Recive8Bit();
- CS_1();
- return read;
- }
- /*
- *********************************************************************************************************
- * 函 數(shù) 名: TM7705_Read2Byte
- * 功能說明: 讀2字節(jié)數(shù)據(jù)
- * 形 參: 無
- * 返 回 值: 讀取的數(shù)據(jù)(16位)
- *********************************************************************************************************
- */
- static uint16_t TM7705_Read2Byte(void)
- {
- uint16_t read;
- CS_0();
- read = TM7705_Recive8Bit();
- read <<= 8;
- read += TM7705_Recive8Bit();
- CS_1();
- return read;
- }
- /*
- *********************************************************************************************************
- * 函 數(shù) 名: TM7705_Read3Byte
- * 功能說明: 讀3字節(jié)數(shù)據(jù)
- * 形 參: 無
- * 返 回 值: 讀取到的數(shù)據(jù)(24bit) 高8位固定為0.
- *********************************************************************************************************
- */
- static uint32_t TM7705_Read3Byte(void)
- {
- uint32_t read;
- CS_0();
- read = TM7705_Recive8Bit();
- read <<= 8;
- read += TM7705_Recive8Bit();
- read <<= 8;
- read += TM7705_Recive8Bit();
- CS_1();
- return read;
- }
- /*
- *********************************************************************************************************
- * 函 數(shù) 名: TM7705_WaitDRDY
- * 功能說明: 等待內(nèi)部操作完成。 自校準(zhǔn)時間較長,需要等待。
- * 形 參: 無
- * 返 回 值: 無
- *********************************************************************************************************
- */
- static void TM7705_WaitDRDY(void)
- {
- uint32_t i;
- for (i = 0; i < 8000; i++)
- {
- if (DRDY_IS_LOW())
- {
- break;
- }
- }
- if (i >= 8000)
- {
- printf("TM7705_WaitDRDY() 芯片應(yīng)答超時 ...\r\n"); /* 調(diào)試語句. 用語排錯 */
- printf("重新同步SPI接口時序\r\n"); /* 調(diào)試語句. 用語排錯 */
- TM7705_SyncSPI(); /* 同步SPI接口時序 */
- bsp_DelayMS(5);
- }
- }
- /*
- *********************************************************************************************************
- * 函 數(shù) 名: TM7705_WriteReg
- * 功能說明: 寫指定的寄存器
- * 形 參: _RegID : 寄存器ID
- * _RegValue : 寄存器值。 對于8位的寄存器,取32位形參的低8bit
- * 返 回 值: 無
- *********************************************************************************************************
- */
- void TM7705_WriteReg(uint8_t _RegID, uint32_t _RegValue)
- {
- uint8_t bits;
- switch (_RegID)
- {
- case REG_COMM: /* 通信寄存器 */
- case REG_SETUP: /* 設(shè)置寄存器 8bit */
- case REG_CLOCK: /* 時鐘寄存器 8bit */
- bits = 8;
- break;
- case REG_ZERO_CH1: /* CH1 偏移寄存器 24bit */
- case REG_FULL_CH1: /* CH1 滿量程寄存器 24bit */
- case REG_ZERO_CH2: /* CH2 偏移寄存器 24bit */
- case REG_FULL_CH2: /* CH2 滿量程寄存器 24bit*/
- bits = 24;
- break;
- case REG_DATA: /* 數(shù)據(jù)寄存器 16bit */
- default:
- return;
- }
- TM7705_WriteByte(_RegID | WRITE); /* 寫通信寄存器, 指定下一步是寫操作,并指定寫哪個寄存器 */
- if (bits == 8)
- {
- TM7705_WriteByte((uint8_t)_RegValue);
- }
- else /* 24bit */
- {
- TM7705_Write3Byte(_RegValue);
- }
- }
- /*
- *********************************************************************************************************
- * 函 數(shù) 名: TM7705_ReadReg
- * 功能說明: 寫指定的寄存器
- * 形 參: _RegID : 寄存器ID
- * _RegValue : 寄存器值。 對于8位的寄存器,取32位形參的低8bit
- * 返 回 值: 讀到的寄存器值。 對于8位的寄存器,取32位形參的低8bit
- *********************************************************************************************************
- */
- uint32_t TM7705_ReadReg(uint8_t _RegID)
- {
- uint8_t bits;
- uint32_t read;
- switch (_RegID)
- {
- case REG_COMM: /* 通信寄存器 */
- case REG_SETUP: /* 設(shè)置寄存器 8bit */
- case REG_CLOCK: /* 時鐘寄存器 8bit */
- bits = 8;
- break;
- case REG_ZERO_CH1: /* CH1 偏移寄存器 24bit */
- case REG_FULL_CH1: /* CH1 滿量程寄存器 24bit */
- case REG_ZERO_CH2: /* CH2 偏移寄存器 24bit */
- case REG_FULL_CH2: /* CH2 滿量程寄存器 24bit*/
- bits = 24;
- break;
- case REG_DATA: /* 數(shù)據(jù)寄存器 16bit */
- default:
- return 0xFFFFFFFF;
- }
- TM7705_WriteByte(_RegID | READ); /* 寫通信寄存器, 指定下一步是寫操作,并指定寫哪個寄存器 */
- if (bits == 16)
- {
- read = TM7705_Read2Byte();
- }
- else if (bits == 8)
- {
- read = TM7705_ReadByte();
- }
- else /* 24bit */
- {
- read = TM7705_Read3Byte();
- }
- return read;
- }
- /*
- *********************************************************************************************************
- * 函 數(shù) 名: TM7705_CalibSelf
- * 功能說明: 啟動自校準(zhǔn). 內(nèi)部自動短接AIN+ AIN-校準(zhǔn)0位,內(nèi)部短接到Vref 校準(zhǔn)滿位。此函數(shù)執(zhí)行過程較長,
- * 實測約 180ms
- * 形 參: _ch : ADC通道,1或2
- * 返 回 值: 無
- *********************************************************************************************************
- */
- void TM7705_CalibSelf(uint8_t _ch)
- {
- if (_ch == 1)
- {
- /* 自校準(zhǔn)CH1 */
- TM7705_WriteByte(REG_SETUP | WRITE | CH_1); /* 寫通信寄存器,下一步是寫設(shè)置寄存器,通道1 */
- TM7705_WriteByte(MD_CAL_SELF | __CH1_GAIN_BIPOLAR_BUF | FSYNC_0);/* 啟動自校準(zhǔn) */
- TM7705_WaitDRDY(); /* 等待內(nèi)部操作完成 --- 時間較長,約180ms */
- }
- else if (_ch == 2)
- {
- /* 自校準(zhǔn)CH2 */
- TM7705_WriteByte(REG_SETUP | WRITE | CH_2); /* 寫通信寄存器,下一步是寫設(shè)置寄存器,通道2 */
- TM7705_WriteByte(MD_CAL_SELF | __CH2_GAIN_BIPOLAR_BUF | FSYNC_0); /* 啟動自校準(zhǔn) */
- TM7705_WaitDRDY(); /* 等待內(nèi)部操作完成 --- 時間較長,約180ms */
- }
- }
- /*
- *********************************************************************************************************
- * 函 數(shù) 名: TM7705_SytemCalibZero
- * 功能說明: 啟動系統(tǒng)校準(zhǔn)零位. 請將AIN+ AIN-短接后,執(zhí)行該函數(shù)。校準(zhǔn)應(yīng)該由主程序控制并保存校準(zhǔn)參數(shù)。
- * 執(zhí)行完畢后?梢酝ㄟ^ TM7705_ReadReg(REG_ZERO_CH1) 和 TM7705_ReadReg(REG_ZERO_CH2) 讀取校準(zhǔn)參數(shù)。
- * 形 參: _ch : ADC通道,1或2
- * 返 回 值: 無
- *********************************************************************************************************
- */
- void TM7705_SytemCalibZero(uint8_t _ch)
- {
- if (_ch == 1)
- {
- /* 校準(zhǔn)CH1 */
- TM7705_WriteByte(REG_SETUP | WRITE | CH_1); /* 寫通信寄存器,下一步是寫設(shè)置寄存器,通道1 */
- TM7705_WriteByte(MD_CAL_ZERO | __CH1_GAIN_BIPOLAR_BUF | FSYNC_0);/* 啟動自校準(zhǔn) */
- TM7705_WaitDRDY(); /* 等待內(nèi)部操作完成 */
- }
- else if (_ch == 2)
- {
- /* 校準(zhǔn)CH2 */
- TM7705_WriteByte(REG_SETUP | WRITE | CH_2); /* 寫通信寄存器,下一步是寫設(shè)置寄存器,通道1 */
- TM7705_WriteByte(MD_CAL_ZERO | __CH2_GAIN_BIPOLAR_BUF | FSYNC_0); /* 啟動自校準(zhǔn) */
- TM7705_WaitDRDY(); /* 等待內(nèi)部操作完成 */
- }
- }
- /*
- *********************************************************************************************************
- * 函 數(shù) 名: TM7705_SytemCalibFull
- * 功能說明: 啟動系統(tǒng)校準(zhǔn)滿位. 請將AIN+ AIN-接最大輸入電壓源,執(zhí)行該函數(shù)。校準(zhǔn)應(yīng)該由主程序控制并保存校準(zhǔn)參數(shù)。
- * 執(zhí)行完畢后?梢酝ㄟ^ TM7705_ReadReg(REG_FULL_CH1) 和 TM7705_ReadReg(REG_FULL_CH2) 讀取校準(zhǔn)參數(shù)。
- * 形 參: _ch : ADC通道,1或2
- * 返 回 值: 無
- *********************************************************************************************************
- */
- void TM7705_SytemCalibFull(uint8_t _ch)
- {
- if (_ch == 1)
- {
- /* 校準(zhǔn)CH1 */
- TM7705_WriteByte(REG_SETUP | WRITE | CH_1); /* 寫通信寄存器,下一步是寫設(shè)置寄存器,通道1 */
- TM7705_WriteByte(MD_CAL_FULL | __CH1_GAIN_BIPOLAR_BUF | FSYNC_0);/* 啟動自校準(zhǔn) */
- TM7705_WaitDRDY(); /* 等待內(nèi)部操作完成 */
- }
- else if (_ch == 2)
- {
- /* 校準(zhǔn)CH2 */
- TM7705_WriteByte(REG_SETUP | WRITE | CH_2); /* 寫通信寄存器,下一步是寫設(shè)置寄存器,通道1 */
- TM7705_WriteByte(MD_CAL_FULL | __CH2_GAIN_BIPOLAR_BUF | FSYNC_0); /* 啟動自校準(zhǔn) */
- TM7705_WaitDRDY(); /* 等待內(nèi)部操作完成 */
- }
- }
- /*
- *********************************************************************************************************
- * 函 數(shù) 名: TM7705_ReadAdc1
- * 功能說明: 讀通道1或2的ADC數(shù)據(jù)
- * 形 參: 無
- * 返 回 值: 無
- *********************************************************************************************************
- */
- uint16_t TM7705_ReadAdc(uint8_t _ch)
- {
- uint8_t i;
- uint16_t read = 0;
- /* 為了避免通道切換造成讀數(shù)失效,讀2次 */
- for (i = 0; i < 2; i++)
- {
- TM7705_WaitDRDY(); /* 等待DRDY口線為0 */
- if (_ch == 1)
- {
- TM7705_WriteByte(0x38);
- }
- else if (_ch == 2)
- {
- TM7705_WriteByte(0x39);
- }
- read = TM7705_Read2Byte();
- }
- return read;
- }
- void delay(uint xms) //延時
- {
- uint xx,yy;
- for (xx=xms;xx>0;xx--)
- for(yy=110;yy>0;yy--);
- }
- void lcdwc(uchar lcd_cmd) //液晶命令
- {
- lcden=0;
- lcdrs=0;
- lcdrw=0;
- datlcd=lcd_cmd;
- delay(1);
- lcden=1;
- delay(1);
- lcden=0;
- }
- void lcdwd(uchar lcd_data) //液晶數(shù)據(jù)
- {
- lcden=0;
- lcdrs=1;
- lcdrw=0;
- datlcd=lcd_data;
- delay(1);
- lcden=1;
- delay(1);
- lcden=0;
- }
- void lcdxy(uchar hlcd,uchar addlcd,uchar dtlcd) //定位寫數(shù)據(jù)
- {
- if (hlcd==1)
- {
- lcdwc(0x80+addlcd);
- lcdwd(dtlcd);
- }
- else
- {
- lcdwc(0xc0+addlcd);
- lcdwd(dtlcd);
- }
- }
- void init_1602() //初始化
- {
- delay(5);
- lcdwc(0x01);
- ……………………
- …………限于本文篇幅 余下代碼請從51黑下載附件…………
復(fù)制代碼
下載:
程序.docx
(23.3 KB, 下載次數(shù): 78)
2017-5-11 09:24 上傳
點擊文件名下載附件
AD7705程序
|
|