单片机用的是STM8S103K3,用HT1621B驱动一个四com的断码液晶,折腾好几天了,就是不成功。在论坛看了不少例程,也照着改了还是不成。实在没辙贴出照论坛源码修改的程序,望高人指教。基本外围:晶振11.0592,VCC3.3V,VLCD2.75V。液晶共17PIN,用四个com,和SEGO~SEG12。通电后,液晶无显示,测量HT1621引脚电压,CS脚为0V,WR为3.2,DATA为0.7V,SEG0~SEG12和COM全部都是2.75V。请指教。
#include "ioSTM8S103k3.h"
#include <intrinsics.h>
#define uchar unsigned char
#define uint unsigned int
#define BIAS 0x52 //0b1000 0101 0010 1/3duty 4com
#define SYSDIS 0X00 //0b1000 0000 0000 关振系统荡器和LCD偏压发生器
#define SYSEN 0X02 //0b1000 0000 0010 打开系统振荡器
#define LCDOFF 0X04 //0b1000 0000 0100 关LCD偏压
#define LCDON 0X06 //0b1000 0000 0110 打开LCD偏压
#define XTAL 0x28 //0b1000 0010 1000 外部接时钟
#define RC256 0X30 //0b1000 0011 0000 内部时钟
#define TONEON 0X12 //0b1000 0001 0010 打开声音输出
#define TONEOFF 0X10 //0b1000 0001 0000 关闭声音输出
#define WDTDIS 0X0A //0b1000 0000 1010 禁止看门狗
//HT1621控制位(液晶模块接口定义,根据自已的需要更改)
#define CLS_HT_WR() PD_ODR_ODR3 = 0 //拉低
#define SET_HT_WR() PD_ODR_ODR3 = 1 //拉高
#define CLS_HT_CS() PD_ODR_ODR4 = 0 //拉低
#define SET_HT_CS() PD_ODR_ODR4 = 1 //拉高
#define HT1621_DAT PD_ODR_ODR2 //数据位
#define SET_HT_DATA() PD_ODR_ODR2 = 1 //数据位
#define CLS_HT_DATA() PD_ODR_ODR2 = 0 //数据位
void CLK_Init(void)
{
CLK_ECKR=0x01; //外部时钟寄存器 外部时钟准备就绪,外部时钟开
CLK_SWCR=0x02; //切换控制寄存器 使能自动切换机制
CLK_SWR=0xB4; //主时钟切换寄存器 选择HSE为主时钟源
while (!(CLK_SWCR & 0x08));
CLK_CSSR=0x01; //时钟安全系统寄存器
}
void port_init(void)
{
PB_DDR = 0x10;
PB_CR1 = 0x10;
PB_CR2 = 0x0;
PD_DDR = 0x1c;
PD_CR1 = 0x1c;
PD_CR2 = 0x0;
}
void delay(void)
{
unsigned char i;
for (i = 16; i > 0; i--) //16
{
asm("nop"); ;
}
}
void SendBit_1621(unsigned char data, unsigned char cnt) //data的高cnt位写入HT1621,高位在前
{
unsigned char i;
for (i = 0; i < cnt; i++)
{
if ((data & 0x80) == 0)
{
CLS_HT_DATA();
}
else
{
SET_HT_DATA();
}
delay();
CLS_HT_WR();
// delay();
SET_HT_WR();
//delay();
data <<= 1;
}
}
void SendDataBit_1621(unsigned char data, unsigned char cnt) //data的低cnt位写入HT1621,低位在前
{
unsigned char i;
for (i = 0; i < cnt; i++)
{
if ((data & 0x01) == 0)
{
CLS_HT_DATA();
}
else
{
SET_HT_DATA();
}
delay();
CLS_HT_WR();
//delay();
SET_HT_WR();
//delay();
data >>= 1;
}
}
void SendCmd(unsigned char command)
{
CLS_HT_CS();
SendBit_1621(0x80,3); //写入标志码"100"
SendBit_1621(command,9); //写入9 位数据,其中前8 位为command 命令,最后1 位任意
SET_HT_CS();
}
void Write_1621(unsigned char addr, unsigned char data)
{
CLS_HT_CS();
SendBit_1621(0xa0,3); //写入标志码"101"
SendBit_1621(addr << 2,6); //写入6 位addr
SendDataBit_1621(data<<4,4); //写入data 的低4 位
SET_HT_CS();
}
void WriteAll_1621(unsigned char addr, unsigned char * p, unsigned char cnt)
{
unsigned char i;
CLS_HT_CS();
SendBit_1621(0xa0,3); //写入标志码"101"
SendBit_1621(addr << 2,6); //写入6 位addr
for(i =0; i <cnt; i ++,p++) //连续写入数据
{
SendDataBit_1621(*p,8);
}
SET_HT_CS();
}
void Writetest_1621(void)
{
unsigned int i,p;
CLS_HT_CS();
SendBit_1621(0xa0,3); //写入标志码"101"
SendBit_1621(0,6); //写入6 位addr
for (p = 0; p < 32; p++)
{
for(i = 0; i < 8; i ++) //连续写入数据
{
SendDataBit_1621(p,8);
delay();
}
}
SET_HT_CS();
}
void Cls_1621(void)
{
unsigned int i,p;
CLS_HT_CS();
SendBit_1621(0xa0,8); //写入标志码"101"
SendBit_1621(0,6); //写入6 位addr
for (p = 0; p < 32; p++)
{
for(i = 0; i < 8; i ++) //连续写入数据
{
SendDataBit_1621(0,8);
delay();
}
}
SET_HT_CS();
}
//==============================================================================
void main(void)
{
CLK_Init();
port_init();
SendCmd(BIAS); //设置偏压和占空比
SendCmd(SYSEN); //打开系统振荡器
SendCmd(LCDON); //打开LCD偏压发生器
while (1)
{
Write_1621(0x00,0x09);
Write_1621(0x01,0x0f);
Write_1621(0x02,0x00);
Write_1621(0x03,0x0d);
Write_1621(0x04,0x0e);
Write_1621(0x05,0x0f);
}
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
#include "string.h"
#include "common.h"
#if 0
#define DISP_SEG_S1 (lcd_disp_ram[0] |= SEG_S_COL_DAY_P_TONG)
#define CLEAR_SEG_S1 (lcd_disp_ram[0] &= (~SEG_S_COL_DAY_P_TONG)
#define DISP_SEG_COL1 (lcd_disp_ram[1] |= SEG_S_COL_DAY_P_TONG)
#define CLEAR_SEG_COL1 (lcd_disp_ram[1] &= (~SEG_S_COL_DAY_P_TONG)
#define DISP_SEG_S2 (lcd_disp_ram[2] |= SEG_S_COL_DAY_P_TONG)
#define CLEAR_SEG_S2 (lcd_disp_ram[2] &= (~SEG_S_COL_DAY_P_TONG)
#define DISP_SEG_COL2 (lcd_disp_ram[3] |= SEG_S_COL_DAY_P_TONG)
#define CLEAR_SEG_COL2 (lcd_disp_ram[3] &= (~SEG_S_COL_DAY_P_TONG)
#define DISP_SEG_S3 (lcd_disp_ram[4] |= SEG_S_COL_DAY_P_TONG)
#define CLEAR_SEG_S3 (lcd_disp_ram[4] &= (~SEG_S_COL_DAY_P_TONG)
#define DISP_SEG_P (lcd_disp_ram[5] |= SEG_S_COL_DAY_P_TONG)
#define CLEAR_SEG_P (lcd_disp_ram[5] &= (~SEG_S_COL_DAY_P_TONG)
#define DISP_SEG_DAY (lcd_disp_ram[6] |= SEG_S_COL_DAY_P_TONG)
#define CLEAR_SEG_DAY (lcd_disp_ram[6] &= (~SEG_S_COL_DAY_P_TONG)
#define DISP_SEG_TONG (lcd_disp_ram[7] |= SEG_S_COL_DAY_P_TONG)
#define CLEAR_SEG_TONG (lcd_disp_ram[7] &= (~SEG_S_COL_DAY_P_TONG)
#define DISP_SEG_S4 (lcd_disp_ram[8] |= SEG_S4_T1_COLD_MOTOR)
#define CLEAR_SEG_S4 (lcd_disp_ram[8] &= (~SEG_S4_T1_COLD_MOTOR)
#define DISP_SEG_T1 (lcd_disp_ram[9] |= SEG_S4_T1_COLD_MOTOR)
#define CLEAR_SEG_T1 (lcd_disp_ram[9] &= (~SEG_S4_T1_COLD_MOTOR)
#define DISP_SEG_COLD (lcd_disp_ram[10] |= SEG_S4_T1_COLD_MOTOR)
#define CLEAR_SEG_COLD (lcd_disp_ram[10] &= (~SEG_S4_T1_COLD_MOTOR)
#define DISP_SEG_MOTOR (lcd_disp_ram[11] |= SEG_S4_T1_COLD_MOTOR)
#define CLEAR_SEG_MOTOR (lcd_disp_ram[11] &= (~SEG_S4_T1_COLD_MOTOR)
#define DISP_SEG_HOUR (lcd_disp_ram[8] |= SEG_HOUR_T2_ERR_ICEWATER)
#define CLEAR_SEG_HOUR (lcd_disp_ram[8] &= (~SEG_HOUR_T2_ERR_ICEWATER)
#define DISP_SEG_T2 (lcd_disp_ram[9] |= SEG_HOUR_T2_ERR_ICEWATER)
#define CLEAR_SEG_T2 (lcd_disp_ram[9] &= (~SEG_HOUR_T2_ERR_ICEWATER)
#define DISP_SEG_ERR (lcd_disp_ram[10] |= SEG_HOUR_T2_ERR_ICEWATER)
#define CLEAR_SEG_ERR (lcd_disp_ram[10] &= (~SEG_HOUR_T2_ERR_ICEWATER)
#define DISP_SEG_ICEWATER (lcd_disp_ram[11] |= SEG_HOUR_T2_ERR_ICEWATER)
#define CLEAR_SEG_ICEWATER (lcd_disp_ram[11] &= (~SEG_HOUR_T2_ERR_ICEWATER)
#define DISP_SEG_L (lcd_disp_ram[8] |= SEG_L_T3_HOT_COLDWATER)
#define CLEAR_SEG_L (lcd_disp_ram[8] &= (~SEG_L_T3_HOT_COLDWATER)
#define DISP_SEG_T3 (lcd_disp_ram[9] |= SEG_L_T3_HOT_COLDWATER)
#define CLEAR_SEG_T3 (lcd_disp_ram[9] &= (~SEG_L_T3_HOT_COLDWATER)
#define DISP_SEG_HOT (lcd_disp_ram[10] |= SEG_L_T3_HOT_COLDWATER)
#define CLEAR_SEG_HOT (lcd_disp_ram[10] &= (~SEG_L_T3_HOT_COLDWATER)
#define DISP_SEG_COLDWATER (lcd_disp_ram[11] |= SEG_L_T3_HOT_COLDWATER)
#define CLEAR_SEG_COLDWATER (lcd_disp_ram[11] &= (~SEG_L_T3_HOT_COLDWATER)
#define DISP_SEG_MINUTE (lcd_disp_ram[8] |= SEG_MINUTE_T4_TIME_HOTWATER)
#define CLEAR_SEG_MINUTE (lcd_disp_ram[8] &= (~SEG_MINUTE_T4_TIME_HOTWATER)
#define DISP_SEG_T4 (lcd_disp_ram[9] |= SEG_MINUTE_T4_TIME_HOTWATER)
#define CLEAR_SEG_T4 (lcd_disp_ram[9] &= (~SEG_MINUTE_T4_TIME_HOTWATER)
#define DISP_SEG_TIME (lcd_disp_ram[10] |= SEG_MINUTE_T4_TIME_HOTWATER)
#define CLEAR_SEG_TIME (lcd_disp_ram[10] &= (~SEG_MINUTE_T4_TIME_HOTWATER)
#define DISP_SEG_HOTWATER (lcd_disp_ram[11] |= SEG_MINUTE_T4_TIME_HOTWATER)
#define CLEAR_SEG_HOTWATER (lcd_disp_ram[11] &= (~SEG_MINUTE_T4_TIME_HOTWATER)
#define DISP_SEG_CLOSE (lcd_disp_ram[8] |= SEG_CLOSE_OPEN_ICE)
#define CLEAR_SEG_CLOSE (lcd_disp_ram[8] &= (~SEG_CLOSE_OPEN_ICE)
#define DISP_SEG_OPEN (lcd_disp_ram[9] |= SEG_CLOSE_OPEN_ICE)
#define CLEAR_SEG_OPEN (lcd_disp_ram[9] &= (~SEG_CLOSE_OPEN_ICE)
#define DISP_SEG_ICE (lcd_disp_ram[10] |= SEG_CLOSE_OPEN_ICE)
#define CLEAR_SEG_ICE (lcd_disp_ram[10] &= (~SEG_CLOSE_OPEN_ICE)
#define DISP_SEG_REMAIN (lcd_disp_ram[8] |= SEG_REMAIN_T5_BLANCE)
#define CLEAR_SEG_REMIAN (lcd_disp_ram[8] &= (~SEG_REMAIN_T5_BLANCE)
#define DISP_SEG_T5 (lcd_disp_ram[9] |= SEG_REMAIN_T5_BLANCE)
#define CLEAR_SEG_T5 (lcd_disp_ram[9] &= (~SEG_REMAIN_T5_BLANCE)
#define DISP_SEG_BLANCE (lcd_disp_ram[10] |= SEG_REMAIN_T5_BLANCE)
#define CLEAR_SEG_BLANCE (lcd_disp_ram[10] &= (~SEG_REMAIN_T5_BLANCE)
#define DISP_SEG_CLEAR (lcd_disp_ram[8] |= SEG_CLEAR_INPUT_KEEPTEMP)
#define CLEAR_SEG_CLEAR (lcd_disp_ram[8] &= (~SEG_CLEAR_INPUT_KEEPTEMP)
#define DISP_SEG_INPUT (lcd_disp_ram[9] |= SEG_CLEAR_INPUT_KEEPTEMP)
#define CLEAR_SEG_INPUT (lcd_disp_ram[9] &= (~SEG_CLEAR_INPUT_KEEPTEMP)
#define DISP_SEG_KEEPTEMP (lcd_disp_ram[10] |= SEG_CLEAR_INPUT_KEEPTEMP)
#define CLEAR_SEG_KEEPTEMP (lcd_disp_ram[10] &= (~SEG_REMAIN_T5_BLANCE)
#define DISP_SEG_STOP (lcd_disp_ram[8] |= SEG_STOP_CN_PRICE)
#define CLEAR_SEG_STOP (lcd_disp_ram[8] &= (~SEG_STOP_CN_PRICE)
#define DISP_SEG_CN (lcd_disp_ram[9] |= SEG_STOP_CN_PRICE)
#define CLEAR_SEG_CN (lcd_disp_ram[9] &= (~SEG_STOP_CN_PRICE)
#define DISP_SEG_PRICE (lcd_disp_ram[10] |= SEG_STOP_CN_PRICE)
#define CLEAR_SEG_PRICE (lcd_disp_ram[10] &= (~SEG_STOP_CN_PRICE)
#define LCD_DIGIT_LENGTH 8
#endif
#if 0
//Err Code
const u8 ser_num_err[3]={0,0,1}; //非本系统卡
const u8 user_limit_err[3]={0,0,2}; //限制到达
const u8 user_blance_err[3]={0,0,3}; //钱包错误
const u8 ManageErr[8]={0,0,4}; //管理卡错误
//const u8 LostErr[8]={0x79,0x40,0x40,0x40,0x40,0x3F,0x3F,0x6D}; //挂失错误
//const u8 SortErr[8]={0x79,0x40,0x40,0x40,0x40,0x3F,0x3F,0x7D}; //采集错误
//const u8 SetErr[8]={0x79,0x40,0x40,0x40,0x40,0x3F,0x3F,0x07}; //设置错误
//const u8 RsComErr[8]={0x79,0x40,0x40,0x40,0x40,0x3F,0x3F,0x7F}; //串口通信错误
const u8 SystemParaErr[3]={0,0,9}; //参数错误
const u8 user_card_lost[3]={0,1,0}; //消费卡已经挂失
const u8 user_group_err[3]={0,1,1}; //采集卡序组号错误
const u8 SortCardFull[3]={0,1,2};//采集卡漫
const u8 user_card_valid[3] = {0,1,3}; //有效期到达
const u8 user_card_type[3] = {0,1,4};
//Success code
//const u8 LostSucc[8]={0x3F,0x40,0x40,0x40,0x40,0x3F,0x3F,0x06}; //挂失成功
//const u8 SortSucc[8]={0x3F,0x40,0x40,0x40,0x40,0x3F,0x3F,0x5B}; //采集成功
//const u8 RsComSucc[8]={0x3F,0x40,0x40,0x40,0x40,0x3F,0x3F,0x4F}; //串口通信成功
//const u8 SetSucc[8]={0x3F,0x40,0x40,0x40,0x40,0x3F,0x3F,0x66};
const u8 ManageSucc[3]={0,0,4};
//Other disp code
//const u8 Logo[3] = {0x40,0x6D,0x37,0x79,0x78,0x40}; //SNET
//const u8 GL_Card[3] = {0x40,0x71,0x3E,0x37,0x39,0x40}; //--FUNC--
//const u8 GS_Card[3] = {0x40,0x38,0x3F,0x6D,0x78,0x40};//--LOST--
//const u8 PC_CON[8] = {0x40,0x73,0x39,0x40,0x39,0x3F,0x37,0x40}; //-PC-CON-
//const u8 SORT_CARD[3]={0x40,0x6D,0x3F,0x6F,0x5E,0x40};//采集
//const u8 SET_CARD[3]={0x40,0x6D,0x79,0x07,0x40,0x40}; //设置
//const u8 SC_CARD[8]={0x40,0x40,0x40,0x6D,0x39,0x40,0x40,0x40}; //生产
#endif
void lcd_write_bit(u8 lcd_bit,u8 lcd_write_cnt)
{
u8 i;
RTC_LCD_SCK_H;
nop();nop();nop();nop();nop();nop();
for(i=0;i<lcd_write_cnt;i++)
{
delay_10us(1);
RTC_LCD_SCK_L;
if((lcd_bit & 0x80) == 0x80)
RTC_LCD_IO_H;
else
RTC_LCD_IO_L;
delay_10us(1);
RTC_LCD_SCK_H;
nop();nop();nop();nop();nop();nop();
lcd_bit <<= 1;
RTC_LCD_SCK_H;
}
}
void lcd_cmd_mode(void)
{
lcd_write_bit(0x80,3);
}
void lcd_data_mode(void)
{
lcd_write_bit(0xA0,3);
}
void lcd_write_cmd(u8 lcd_cmd)
{
lcd_write_bit(lcd_cmd, 8);
delay_10us(1);
RTC_LCD_IO_H;
delay_10us(1);
RTC_LCD_SCK_L;
delay_10us(1);
RTC_LCD_SCK_H;
}
void lcd_write_addr(u8 lcd_ram_addr)
{
lcd_ram_addr <<= 2; //ram Hight 2 bit need ingron
lcd_write_bit(lcd_ram_addr, 6);
}
void lcd_write_data(u8 lcd_ram_data)
{
u8 i;
RTC_LCD_SCK_H;
nop();nop();nop();nop();
for(i=0;i<8;i++)
{
delay_10us(1);
RTC_LCD_SCK_L;
if((lcd_ram_data & 0x01) == 0x01)
RTC_LCD_IO_H;
else
RTC_LCD_IO_L;
delay_10us(1);
RTC_LCD_SCK_L;
nop();nop();nop();nop();
lcd_ram_data >>= 1;
RTC_LCD_SCK_H;
}
}
一周热门 更多>