这是我写的程序,大侠帮忙看一下啊!!! 不胜感激!!!
#include<stm8l152c6.h>
#define uint unsigned int
#define uchar unsigned char
uint mask[4] = {0xF000, 0x0F00, 0x00F0, 0x000F};
uchar shift[4] = {12 , 8, 4 , 0};
uchar LCD_DisBuffer[4];
/* 0 1 2 3 4 */
uint NumberMap[10] = {0x3131, 0x2021, 0x3213, 0x3223, 0x2321,
/* 5 6 7 8 9 */
0x1323, 0x1333, 0x3021, 0x3333, 0x3323};
void LCD_Init(void);
void Clock_Init(void);
void ConvertNum(uchar InputNum);
void LCD_WriteFHR(uchar Num);
main()
{
Clock_Init();
LCD_Init();
while (1)
{LCD_WriteFHR(0);}
}
void Clock_Init(void)
{
CLK_SCSR=0x01;//选择HSI作为系统时钟源
CLK_ICKCR = 0x11; // 启用内部RC=16MHZ HSI
while((CLK_ICKCR & 0x02)==0); //等待时钟稳定
CLK_CRTCR |=0x02;//选择HSI作为RTC时钟源
CLK_CRTCR |=0xc0;//64分频 16MHZ/64=250KHZ RTC/2用于LCD时钟 Flcd=125khz (16~500)
CLK_PCKENR2 |=0X0c;//使能LCD RTC时钟
}
void LCD_Init()
{
LCD_CR1 |=0X06;// 1/4 duty , 1/3 bias
LCD_CR2 |=0xEF;//外部电源 3.3v
LCD_FRQ=5<<4;//PS=5 div=0 fck_div= flcd/(2^ps x(16+div))125KHZ/(32X16)=244HZ Fframe=fck_div*duty=244/4=61HZ
LCD_CR1 |=0X28;// 闪烁频率 fB=flcd/128=;
LCD_PM0=0X7f;
LCD_CR3=0X40;//使能
}
void ConvertNum(uchar InputNum)
{
uint Num, tmp = 0;
uchar i;
Num=NumberMap[InputNum];
for(i = 0;i < 4; i++)
{
tmp = Num & mask[i]; //拆分 例如 0 0x3133 被拆分成 3 1 3 3 放到缓存数组中
LCD_DisBuffer[i] = (uchar)(tmp >> (uchar)shift[i]);
}
}
void LCD_WriteFHR(uchar Num)
{
ConvertNum(Num);
//COM0
LCD_RAM1 |= (uchar)(LCD_DisBuffer[0]<<3);
//COM1
LCD_RAM4 |= (uchar)(LCD_DisBuffer[1] << 7);
//COM2
LCD_RAM7 |= (uchar)(LCD_DisBuffer[2]<<3 );
//COM3
LCD_RAM11 |= (uchar)(LCD_DisBuffer[3] << 7);
} |