原有段码液晶程序是stm8的好用,但现在我将stm8中的程序移植到stm32中就一点都不显示。原来stm8的主频是8M,现在stm32f103c8t6的主频设置为72M,调试了好几天,一点都不显示,请原子哥帮忙看一下。
void Delay(uint16_t nCount)
{
while (nCount != 0)
{
nCount--;
}
}
void Ht1621Wr_Data(unsigned char Data,unsigned char cnt) //data的高cnt位写入,高位在前
{
unsigned char i;
for (i=0;i<cnt;i++)
{
Ht1621_WR_0();
if((Data & 0x80)==0x80)
{Ht1621_DAT_1();}
else
{Ht1621_DAT_0();}
Ht1621_WR_1();
Data<<=1;
}
}
void Ht1621WrCmd(unsigned char Cmd)
{
Ht1621_CS_0(); //打开片选使能
Ht1621Wr_Data(0x80,4); //写入命令标志100
Ht1621Wr_Data(Cmd,8); //写入命令数据 //由于没有使用到更改时钟输出命令,直接将command最高位写0
Ht1621_CS_1(); //关闭片选使能
}
void Ht1621WrOneData(unsigned char Addr,unsigned char Data)
{
Ht1621_CS_0();
Ht1621Wr_Data(0xa0,3); //写入数据标志101
Ht1621Wr_Data(Addr<<2,6); //写入地址数据,写入6位地址
Ht1621Wr_Data(Data,4); //写入数据的前四位 7 6 5 4
Ht1621_CS_1();
}
void Ht1621WrAllData(unsigned char Addr,unsigned char *p,unsigned char cnt)
{
unsigned char i;
Ht1621_CS_0();
Ht1621Wr_Data(0xa0,3); //写入数据标志101
Ht1621Wr_Data(Addr<<2,6); //写入地址数据
for (i=0;i<cnt;i++)
{
Ht1621Wr_Data(*p,8); //写入数据
p++;
}
Ht1621_CS_1();
}
void Ht1621_Init(void)
{
Ht1621WrCmd(BIAS);
Ht1621WrCmd(RC256); //使用内部振荡器
//Ht1621WrCmd(XTAL); //使用外部振荡器
Ht1621WrCmd(SYSDIS);
Ht1621WrCmd(WDTDIS1);
Ht1621WrCmd(SYSEN);
Ht1621WrCmd(LCDON);
}
void Display(void)
{
Ht1621WrOneData(0 , DispTab[n4]);
Ht1621WrOneData(1 , DispTab[n4]<<4);//高位在前,先写入前四位,再写入后四位。如2的字模是1010 1101,先写入1010,在写入1101
Ht1621WrOneData(5 , DispTab[n3]);
Ht1621WrOneData(3 , DispTab[n3]<<4);
Ht1621WrOneData(4 , DispTab[n2]);
Ht1621WrOneData(5 , DispTab[n2]<<4);
Ht1621WrOneData(6 , DispTab[n1]);
Ht1621WrOneData(7 , DispTab[n1]<<4);
}
void Display_lcd_dot(void)
{
Ht1621WrOneData(0 , DispTab[n4]|0x10);//P1
//Ht1621WrOneData(2 , DispTab[n3]|0x10); //2P
//Ht1621WrOneData(4 , DispTab[n2]|0x10); //3P
//Ht1621WrOneData(6 , DispTab[n1]|0x10); //4P
}
void data_convertor(unsigned long adc_value)
{
tmp=adc_value; //adc
n4=tmp/1000;
tmp=tmp%1000;
n3=tmp/100;
tmp=tmp%100;
n2=tmp/10;
tmp=tmp%10;
n1=tmp;
}
void main(void)
{
LED_Init(LED1|LED2|LED3);
LED_On(LED1|LED2|LED3);
Delay(0xFFFF);
LED_Off(LED1|LED2|LED3);
Delay(0xFFFF);
Ht1621_GND_0(); //HT1621 power on
Ht1621_VCC_1();
Delay(100); //延时一段时间
Ht1621_Init(); //上电初始化LCD
Delay(100); //延时一段时间
Ht1621WrAllData(0,Ht1621Tab,16);// Clear LCD display
data_convertor(1152);
Display();
Display_lcd_dot();
while (1)
{
}
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
{
int clear=0;
BYTE NB_IoT_SendBuf[4]={0,0,0,0};
BYTE str[8];
int z=0,x=0;
BYTE arr[15];
BYTE arr_char[15];
Init_System();
while(1)
{
delay_ms(100); //延时一段时间
Ht1621WrAllData(0,Ht1621Tab,16);// Clear LCD display
data_convertor(1123);
delay_ms(100);
// Display_lcd_dot();//显示小数点
}
一周热门 更多>