#include "stm8l15x.h"
void display_LCD(unsigned int temp);
void delay(unsigned int time);
void main(void)
{
unsigned int temp;
temp=0;
CLK_PeripheralClockConfig(CLK_Peripheral_RTC, ENABLE); //使能实时时钟
CLK_PeripheralClockConfig(CLK_Peripheral_LCD, ENABLE); //使能LCD时钟
CLK_RTCClockConfig(CLK_RTCCLKSource_HSI,CLK_RTCCLKDiv_8); //选择RTC时钟源
LCD_Init(LCD_Prescaler_64,LCD_Divider_16,LCD_Duty_1_4,LCD_Bias_1_3,LCD_VoltageSource_External ); //LCD初始化
delay(10);
LCD_PortMaskConfig(LCD_PortMaskRegister_1,0XFE); // seg 9,10,11,12,13,14,15为seg口
LCD_PortMaskConfig(LCD_PortMaskRegister_2,0X3F); // seg 16,17,18,19,20,21,为seg口
LCD_ContrastConfig(LCD_Contrast_Level_3); //配置LCD的对比度
LCD_DeadTimeConfig(LCD_DeadTime_0); // 配置LCD液晶的死区时间
LCD_PulseOnDurationConfig(LCD_PulseOnDuration_1); // 配置LCD脉冲持续时间。
LCD_Cmd(ENABLE); //使能LCD控制器
while (1)
{
display_LCD(temp);
temp++;
if(temp==100)
temp=0;
}
}
//////**********************************************************************//////////
//////*****************************LCD显示函数*****************************//////////
void display_LCD(unsigned int temp)
{
unsigned int shi,ge;
shi=temp/10;
ge=temp%10;
//********************十位显示********************//////////
switch(shi)
{
case 1:
{
//显示十位1
// LCD_WriteRAM(LCD_RAMRegister_5,0X40);
assert_param(IS_LCD_RAM_REGISTER(LCD_RAMRegister_5));
LCD->RAM[LCD_RAMRegister_5] = 0x40|(LCD->RAM[LCD_RAMRegister_5]);
// LCD_WriteRAM(LCD_RAMRegister_12,0X40);
assert_param(IS_LCD_RAM_REGISTER(LCD_RAMRegister_12));
LCD->RAM[LCD_RAMRegister_12] = 0x40|(LCD->RAM[LCD_RAMRegister_12]);
break;
}
case 2:
{
//显示十位2
// LCD_WriteRAM(LCD_RAMRegister_2,0X08);
assert_param(IS_LCD_RAM_REGISTER(LCD_RAMRegister_2));
LCD->RAM[LCD_RAMRegister_2] = 0x08|(LCD->RAM[LCD_RAMRegister_2]);
// LCD_WriteRAM(LCD_RAMRegister_5,0X80);
assert_param(IS_LCD_RAM_REGISTER(LCD_RAMRegister_5));
LCD->RAM[LCD_RAMRegister_5] = 0x80|(LCD->RAM[LCD_RAMRegister_5]);
// LCD_WriteRAM(LCD_RAMRegister_9,0X04);
assert_param(IS_LCD_RAM_REGISTER(LCD_RAMRegister_9));
LCD->RAM[LCD_RAMRegister_9] = 0x04|(LCD->RAM[LCD_RAMRegister_9]);
// LCD_WriteRAM(LCD_RAMRegister_12,0XC0);
assert_param(IS_LCD_RAM_REGISTER(LCD_RAMRegister_12));
LCD->RAM[LCD_RAMRegister_12] = 0xC0|(LCD->RAM[LCD_RAMRegister_12]);
break;
}
case 3:
{
//显示十位3
// LCD_WriteRAM(LCD_RAMRegister_2,0X08);
assert_param(IS_LCD_RAM_REGISTER(LCD_RAMRegister_2));
LCD->RAM[LCD_RAMRegister_2] = 0x08|(LCD->RAM[LCD_RAMRegister_2]);
// LCD_WriteRAM(LCD_RAMRegister_5,0X40);
assert_param(IS_LCD_RAM_REGISTER(LCD_RAMRegister_5));
LCD->RAM[LCD_RAMRegister_5] = 0x40|(LCD->RAM[LCD_RAMRegister_5]);
// LCD_WriteRAM(LCD_RAMRegister_9,0X04);
assert_param(IS_LCD_RAM_REGISTER(LCD_RAMRegister_9));
LCD->RAM[LCD_RAMRegister_9] = 0x04|(LCD->RAM[LCD_RAMRegister_9]);
// LCD_WriteRAM(LCD_RAMRegister_12,0XC0);
assert_param(IS_LCD_RAM_REGISTER(LCD_RAMRegister_12));
LCD->RAM[LCD_RAMRegister_12] = 0xC0|(LCD->RAM[LCD_RAMRegister_12]);
break;
}
case 4:
{
//显示十位4
// LCD_WriteRAM(LCD_RAMRegister_5,0X40);
assert_param(IS_LCD_RAM_REGISTER(LCD_RAMRegister_5));
LCD->RAM[LCD_RAMRegister_5] = 0x40|(LCD->RAM[LCD_RAMRegister_5]);
// LCD_WriteRAM(LCD_RAMRegister_9,0X0C);
assert_param(IS_LCD_RAM_REGISTER(LCD_RAMRegister_9));
LCD->RAM[LCD_RAMRegister_9] = 0x0C|(LCD->RAM[LCD_RAMRegister_9]);
// LCD_WriteRAM(LCD_RAMRegister_12,0X40);
assert_param(IS_LCD_RAM_REGISTER(LCD_RAMRegister_12));
LCD->RAM[LCD_RAMRegister_12] = 0x40|(LCD->RAM[LCD_RAMRegister_12]);
break;
}
case 5:
{
//显示十位5
// LCD_WriteRAM(LCD_RAMRegister_2,0X08);
assert_param(IS_LCD_RAM_REGISTER(LCD_RAMRegister_2));
LCD->RAM[LCD_RAMRegister_2] = 0x08|(LCD->RAM[LCD_RAMRegister_2]);
//LCD_WriteRAM(LCD_RAMRegister_5,0X40);
assert_param(IS_LCD_RAM_REGISTER(LCD_RAMRegister_5));
LCD->RAM[LCD_RAMRegister_5] = 0x40|(LCD->RAM[LCD_RAMRegister_5]);
// LCD_WriteRAM(LCD_RAMRegister_9,0X0C);
assert_param(IS_LCD_RAM_REGISTER(LCD_RAMRegister_9));
LCD->RAM[LCD_RAMRegister_9] = 0x0C|(LCD->RAM[LCD_RAMRegister_9]);
// LCD_WriteRAM(LCD_RAMRegister_12,0X80);
assert_param(IS_LCD_RAM_REGISTER(LCD_RAMRegister_12));
LCD->RAM[LCD_RAMRegister_12] = 0x80|(LCD->RAM[LCD_RAMRegister_12]);
break;
}
|