本帖最后由 ljx200710 于 2017-9-11 09:47 编辑
//我自己编写的RTC设置时间和解码时间,同时加入闹钟功能,亲测通过。特别注意的是设置时间函数需要打开后备电源和使能后备区域写功能。
//main.c
////////////////////////////////////////////////////////////////////////////////////////////
#include<stm32f10x.h>
#include<stm32f10x_conf.h>
#include "stm32lcd12864.h"
#include<stdio.h>
#define LED GPIO_Pin_6|GPIO_Pin_7|GPIO_Pin_8|GPIO_Pin_9
#define LED_PORT GPIOC
void GPIO_Configuration(void);
void USART_Configuration(void);
void NVIC_Configuration(void);
void DMA_Configuration(void);
void RTC_Init(void);
u16 buffer[10]={0};
unsigned int i;
unsigned char const number[]={"0123456789:-"};
unsigned char const tab[]={"日期 "};
unsigned char const tab1[]={"时间 "};
unsigned char const tab2[]={"电压 "};
unsigned char const runnian[]={0,31,29,31,30,31,30,31,31,30,31,30,31};
unsigned char const pingnian[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
u8 ruannian_flag=0;//闰年标志位
u32 TimeData=0,hour=0,min=0,sec=0;
u8 time_bz=0;
u8 nn=0,yy=0,rr=0;
void delay(u32 t)
{
while(--t);
}
/////////////////////////////////////////////////////////////////////////////
void settime(u8 nn,u8 yy,u8 rr,u8 hh,u8 mm,u8 sec)//时间设定编码,有效期为2000年1月1日00:00:00-2099年12月31日23:59:59
{
u32 realtime,day;
u16 yue_day=0;
if(nn==0)day=0;
else day=366+(nn-1)*365.25;
if((nn%4)==0) for(i=1;i<yy;i++) yue_day+=runnian;
else for(i=1;i<yy;i++) yue_day+=pingnian;
day+=(yue_day+rr-1);
realtime=day*24*3600+hh%24*3600+mm%60*60+sec%60;
RTC_SetCounter(realtime);
}
void setalarm(u8 nn1,u8 yy1,u8 rr1,u8 hh1,u8 mm1,u8 sec1)//设置闹钟
{
u32 realt,day;
u16 yue_day=0;
if(nn1==0)day=0;
else day=366+(nn1-1)*365.25;
if((nn1%4)==0)for(i=1;i<yy1;i++) yue_day+=runnian;
else for(i=1;i<yy1;i++) yue_day+=pingnian;
day+=(yue_day+rr1-1);
//RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR|RCC_APB1Periph_BKP,ENABLE);
PWR_BackupAccessCmd(ENABLE);
RTC_WaitForLastTask();//等待RTC寄存器完成
realt=day*24*3600+hh1%24*3600+mm1%60*60+sec1%60;
RTC_SetAlarm(realt);//设置闹钟
RTC_WaitForLastTask();//等待RTC寄存器完成
PWR_BackupAccessCmd(DISABLE);
}
void SetAlarm_Seconds(u32 sec)//设置倒计时闹钟,单位为秒
{
u32 realt;
//RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR|RCC_APB1Periph_BKP,ENABLE);
PWR_BackupAccessCmd(ENABLE);
RTC_WaitForLastTask();//等待RTC寄存器完成
realt=RTC_GetCounter()+sec;//获取计时器的值
RTC_SetAlarm(realt);//设置闹钟
RTC_WaitForLastTask();//等待RTC寄存器完成
PWR_BackupAccessCmd(DISABLE);
//printf("realtime=%d\r\n",realt);
}
///////////////////////////////////////////////////////////////////////////////////////
void decodetime(void)
{
u32 realtime,day;
signed short int yearday=0;
realtime=RTC_GetCounter();//获取计时器的值
hour=(realtime/3600)%24;
min=(realtime/60)%60;
sec=realtime%60;
day=realtime/86400;//获取天数
nn=day/365.25;//相隔几年
if((nn%4)==0)ruannian_flag=1;//先判断是否为闰年
else ruannian_flag=0;
yearday=(signed short int)(day-365.25*nn);//得到当年的天数
if(ruannian_flag==1)
{
for(yy=1;(yearday-=runnian[yy])>=0;yy++);//求月份yy
yearday=yearday+runnian[yy];
}
else
{
for(yy=1;(yearday-=pingnian[yy])>=0;yy++);//求月份yy
yearday=yearday+pingnian[yy];
}
rr=yearday+1;
}
//////////////////////////////////////////////////////////////////////////////////////
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Pin=LED;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_10MHz;
GPIO_Init(LED_PORT,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IN_FLOATING;
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_10;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_10MHz;
GPIO_Init(GPIOA,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_9;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_10MHz;
GPIO_Init(GPIOA,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IN_FLOATING;
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_8;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_10MHz;
GPIO_Init(GPIOB,&GPIO_InitStructure);
}
void ADC_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
ADC_InitTypeDef ADC_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1,ENABLE);
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AIN;//模拟输入通道
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_2;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_10MHz;
GPIO_Init(GPIOA,&GPIO_InitStructure);
///////////////////////////////////////////////////////////////////////
ADC_DeInit(ADC1);
ADC_InitStructure.ADC_ContinuousConvMode=ENABLE;
ADC_InitStructure.ADC_DataAlign=ADC_DataAlign_Right;
ADC_InitStructure.ADC_ExternalTrigConv=ADC_ExternalTrigConv_None;
ADC_InitStructure.ADC_Mode=ADC_Mode_Independent;
ADC_InitStructure.ADC_NbrOfChannel=1;//只有一个转换通道
ADC_InitStructure.ADC_ScanConvMode=DISABLE;
ADC_Init(ADC1,&ADC_InitStructure);
ADC_RegularChannelConfig(ADC1,ADC_Channel_2,1,ADC_SampleTime_239Cycles5);
ADC_DMACmd(ADC1,ENABLE);
ADC_Cmd(ADC1,ENABLE);
//ADC_SoftwareStartConvCmd(ADC1,ENABLE);
ADC_ResetCalibration(ADC1);
while(ADC_GetResetCalibrationStatus(ADC1));
ADC_StartCalibration(ADC1);
while(ADC_GetCalibrationStatus(ADC1));
ADC_SoftwareStartConvCmd(ADC1,ENABLE);
}
void USART_Configuration(void)
{
USART_InitTypeDef USART_InitStructure;
USART_InitStructure.USART_BaudRate=115200;
USART_InitStructure.USART_HardwareFlowControl=USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode=USART_Mode_Rx|USART_Mode_Tx;
USART_InitStructure.USART_Parity=USART_Parity_No;
USART_InitStructure.USART_StopBits=USART_StopBits_1;
USART_InitStructure.USART_WordLength=USART_WordLength_8b;
USART_Init(USART1,&USART_InitStructure);
USART_DMACmd(USART1,USART_DMAReq_Tx,ENABLE);
USART_Cmd(USART1,ENABLE);
//USART_ITConfig(USART1,USART_IT_RXNE,ENABLE);
USART_ClearFlag(USART1,USART_FLAG_TC);
}
void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
EXTI_InitTypeDef EXTI_InitStructure;
NVIC_SetPriorityGrouping(NVIC_PriorityGroup_1);
// NVIC_InitStructure.NVIC_IRQChannel=USART1_IRQn;
// NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=0;
// NVIC_InitStructure.NVIC_IRQChannelSubPriority=1;
// NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
// NVIC_Init(&NVIC_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel=RTC_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority=1;
NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
NVIC_Init(&NVIC_InitStructure);
// NVIC_InitStructure.NVIC_IRQChannel=RTCAlarm_IRQn;
// NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1;
// NVIC_InitStructure.NVIC_IRQChannelSubPriority=0;
// NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
// NVIC_Init(&NVIC_InitStructure);
//
// EXTI_InitStructure.EXTI_Line=EXTI_Line17;
// EXTI_InitStructure.EXTI_LineCmd=ENABLE;
// EXTI_InitStructure.EXTI_Mode=EXTI_Mode_Interrupt;
// EXTI_InitStructure.EXTI_Trigger=EXTI_Trigger_Falling;
// EXTI_Init(&EXTI_InitStructure);
// EXTI_ClearITPendingBit(EXTI_Line17);//使用RTC闹钟中断时不需要外部中断线,而使用RTC—ALARM中断时需要使用外部中断线
}
void DMA_Configuration(void)
{
DMA_InitTypeDef DMA_InitStructure;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1|RCC_AHBPeriph_DMA2,ENABLE);
DMA_InitStructure.DMA_BufferSize=2;
DMA_InitStructure.DMA_DIR=DMA_DIR_PeripheralDST;
DMA_InitStructure.DMA_M2M=DMA_M2M_Disable;
DMA_InitStructure.DMA_MemoryBaseAddr=(u32)buffer;
DMA_InitStructure.DMA_MemoryDataSize=DMA_PeripheralDataSize_Byte;
DMA_InitStructure.DMA_MemoryInc=DMA_MemoryInc_Enable;
DMA_InitStructure.DMA_Mode=DMA_Mode_Circular;
DMA_InitStructure.DMA_PeripheralBaseAddr=(u32)&USART1->DR;
DMA_InitStructure.DMA_PeripheralDataSize=DMA_MemoryDataSize_Byte;
DMA_InitStructure.DMA_PeripheralInc=DMA_PeripheralInc_Disable;
DMA_InitStructure.DMA_Priority=DMA_Priority_Medium;
DMA_Init(DMA1_Channel4,&DMA_InitStructure);
DMA_InitStructure.DMA_BufferSize=10;
DMA_InitStructure.DMA_DIR=DMA_DIR_PeripheralSRC;
DMA_InitStructure.DMA_M2M=DMA_M2M_Disable;
DMA_InitStructure.DMA_MemoryBaseAddr=(u32)buffer;
DMA_InitStructure.DMA_MemoryDataSize=DMA_PeripheralDataSize_HalfWord;
DMA_InitStructure.DMA_MemoryInc=DMA_MemoryInc_Enable;
DMA_InitStructure.DMA_Mode=DMA_Mode_Circular;
DMA_InitStructure.DMA_PeripheralBaseAddr=(u32)&ADC1->DR;
DMA_InitStructure.DMA_PeripheralDataSize=DMA_MemoryDataSize_HalfWord;
DMA_InitStructure.DMA_PeripheralInc=DMA_PeripheralInc_Disable;
DMA_InitStructure.DMA_Priority=DMA_Priority_High;
DMA_Init(DMA1_Channel1,&DMA_InitStructure);
//DMA_Cmd(DMA1_Channel4,ENABLE);//USART1_DMA开启
DMA_Cmd(DMA1_Channel1,ENABLE);//ADC1_DMA开启
}
void RTC_Configuration(void)
{
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR|RCC_APB1Periph_BKP,ENABLE);
PWR_BackupAccessCmd(ENABLE);
BKP_DeInit();
RCC_LSEConfig(RCC_LSE_ON);//使能外部低速晶振
//RCC_LSICmd(ENABLE);
while(RCC_GetFlagStatus(RCC_FLAG_LSERDY)==RESET);//等待外部低速晶振就绪
//LED_PORT->ODR&=~(LED);
RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);//选择RTC外部时钟为32.768k
RCC_RTCCLKCmd(ENABLE);//使能RTC时钟
RTC_WaitForSynchro();//等待RTC时钟与APB1时钟同步
RTC_WaitForLastTask();//等待RTC寄存器完成
//RTC_EnterConfigMode();//进入配置模式
RTC_ITConfig(RTC_IT_SEC,ENABLE);
RTC_WaitForLastTask();//等待RTC寄存器完
RTC_SetPrescaler(32767);
RTC_WaitForLastTask();//等待RTC寄存器完
}
void RTC_Init(void)
{
if(BKP_ReadBackupRegister(BKP_DR1)!=0x69a9)//第一次配置时钟
{
RTC_Configuration();//RTC初始化
//RTC_SetCounter(72600);
settime(17,9,9,17,56,0);
//RTC_ExitConfigMode();//退出配置模式
BKP_WriteBackupRegister(BKP_DR1,0x69a9);//写入用户配置标志
}
else
{
//RCC_LSICmd(ENABLE);
//RCC_LSEConfig(RCC_LSE_ON);//使能外部低速晶振
RTC_WaitForSynchro();//等待RTC时钟与APB1时钟同步
RTC_WaitForLastTask();//等待RTC寄存器完成
RTC_ITConfig(RTC_IT_ALR|RTC_IT_SEC,ENABLE);//秒中断使能断电或者复位后不保存的
}
}
int fputc(int ch,FILE *f)
{
USART_SendData(USART1,(u8)ch);
while(USART_GetFlagStatus(USART1,USART_FLAG_TXE)==RESET);
return ch;
}
void RTC_IRQHandler(void)
{
if(RTC_GetFlagStatus(RTC_IT_SEC)==SET)//秒中断
{
RTC_ClearITPendingBit(RTC_IT_SEC);
time_bz=1;
}
//////////////////////////////////////////////////////
if(RTC_GetFlagStatus(RTC_IT_ALR)==SET)//闹钟中断
{
LED_PORT->ODR^=(LED);//点亮LED灯
RTC_ClearITPendingBit(RTC_IT_ALR);
RTC_WaitForLastTask();//等待RTC寄存器完
SetAlarm_Seconds(10);
//RTC_ITConfig(RTC_IT_ALR,DISABLE);//退出闹钟中断功能
}
}
/*
void RTCAlarm_IRQHandler(void)
{
//////////////////////////////////////////////////////
EXTI_ClearITPendingBit(EXTI_Line17);
if(RTC_GetFlagStatus(RTC_IT_ALR)==SET)//闹钟中断
{
LED_PORT->ODR^=(LED);//点亮LED灯
RTC_ClearITPendingBit(RTC_IT_ALR);
RTC_WaitForLastTask();//等待RTC寄存器完
SetAlarm_Seconds(10);
//RTC_ITConfig(RTC_IT_ALR,DISABLE);//退出闹钟中断功能
}
}
*/
void lcd_timedisp(void)
{
u8 nn_sw,nn_gw,yy_sw,yy_gw,rr_sw,rr_gw,hour_sw,hour_gw,min_sw,min_gw,sec_sw,sec_gw;
decodetime();
nn_sw=nn/10%10;
nn_gw=nn%10;
yy_sw=yy/10%10;
yy_gw=yy%10;
rr_sw=rr/10%10;
rr_gw=rr%10;
hour_sw=hour/10%10;
hour_gw=hour%10;
min_sw=min/10%10;
min_gw=min%10;
sec_sw=sec/10%10;
sec_gw=sec%10;
lcd_pos(2,0);
for(i=0;i<5;i++)
lcd_wdat(tab);
lcd_wdat(number[nn_sw]);
lcd_wdat(number[nn_gw]);
lcd_wdat('-');
lcd_wdat(number[yy_sw]);
lcd_wdat(number[yy_gw]);
lcd_wdat('-');
lcd_wdat(number[rr_sw]);
lcd_wdat(number[rr_gw]);
lcd_pos(3,0);
for(i=0;i<5;i++)
lcd_wdat(tab1);
lcd_wdat(number[hour_sw]);
lcd_wdat(number[hour_gw]);
lcd_wdat(':');
lcd_wdat(number[min_sw]);
lcd_wdat(number[min_gw]);
lcd_wdat(':');
lcd_wdat(number[sec_sw]);
lcd_wdat(number[sec_gw]);
//if(sec_gw==0)LED_PORT->ODR&=~(LED);
//else LED_PORT->ODR=(LED);
}
void lcd_adcdis(void)
{
u16 Voltage;
u8 Vqw,Vbw,Vsw,Vgw;
float ADC_Result=0;
for(i=0;i<10;i++)
{
ADC_Result+=buffer; //取近十次转换的DMA均值
//while(ADC_GetFlagStatus(ADC1,ADC_FLAG_EOC)==0);
//ADC_ClearFlag(ADC1,ADC_FLAG_EOC);
//ADC_Result+=ADC_GetConversionValue(ADC1); //取近十次ADC转换的均值
}
//ADC_Result/=10;
Voltage=ADC_Result/4095*328;
Vqw=Voltage/1000%10;
Vbw=Voltage/100%10;
Vsw=Voltage/10%10;
//Vgw=Voltage%10;
lcd_pos(4,0);
for(i=0;i<5;i++)
lcd_wdat(tab2);
lcd_wdat(number[Vqw]);
lcd_wdat('.');
lcd_wdat(number[Vbw]);
lcd_wdat(number[Vsw]);
//lcd_wdat(number[Vgw]);
lcd_wdat('V');
}
int main(void)
{
SystemInit();
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC|RCC_APB2Periph_AFIO,ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1|RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB,ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR|RCC_APB1Periph_BKP,ENABLE);
USART_Configuration();
GPIO_Configuration();
ADC_Configuration();
NVIC_Configuration();
LED_PORT->ODR&=~(LED);
DMA_Configuration();
time_bz=0;
lcd_init();
RTC_Init();
lcd_pos_wstr(1,2,"RTC_TEST!");
SetAlarm_Seconds(101 );
//setalarm(17,9,3,20,28,30);
while(1)
{
if(time_bz)
{
time_bz=0;
//printf("时间:%0.2d-%0.2d-%0.2d %0.2d:%0.2d:%0.2d \r\n",nn,yy,rr,hour,min,sec);
lcd_timedisp();
}
lcd_adcdis();
if((GPIOB->IDR&(1<<8))==0)//如果PB8按下,就进入休眠模式
{
//PWR_WakeUpPinCmd(ENABLE);//使能引脚PA0唤醒,休眠之后IO口停止供电,那么PA0的软件上拉失效,PA0必须使用外部的硬件上拉或者下拉
SetAlarm_Seconds(10);//设置倒计时闹钟,10秒后唤醒系统,由于是休眠模式,倒计时结束系统会复位
PWR_EnterSTANDBYMode();//进入休眠模式,唤醒后系统复位
}
}
}
/////////////////////////////////////////////////////////////////////////
//stm32lcd12864.h
///////////////////////////////////////////////////////
#ifndef __STM32LCD12864_H__
#define __STM32LCD12864_H__
#include<stm32f10x.h>
//////////////////////LCD12864??//////////////////////////////
#define RCC_LCDDataPort RCC_APB2Periph_GPIOC
#define RCC_LCDControlPort RCC_APB2Periph_GPIOE
#define LCD_DATA_Port GPIOE
#define LCD_DATA_Pin (GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15)
#define LCD_Control_Port GPIOC
#define LCD_Control_pin (LCD_RS | LCD_RW | LCD_EN|GPIO_Pin_3)
#define LCD_RS GPIO_Pin_0
#define LCD_RW GPIO_Pin_1
#define LCD_EN GPIO_Pin_2
/////////////////////////////////////////////////////////////
#define LCD_RS0 GPIO_ResetBits(LCD_Control_Port,LCD_RS)
#define LCD_RS1 GPIO_SetBits(LCD_Control_Port,LCD_RS)
#define LCD_RW0 GPIO_ResetBits(LCD_Control_Port,LCD_RW)
#define LCD_RW1 GPIO_SetBits(LCD_Control_Port,LCD_RW)
#define LCD_EN1 GPIO_ResetBits(LCD_Control_Port,LCD_EN)
#define LCD_EN0 GPIO_SetBits(LCD_Control_Port,LCD_EN)
#define LCD_WriteData(data) GPIO_Write(LCD_DATA_Port,(0xff00&(data<<8)))
//#define LCD_ReadData(data) (0x00ff&GPIO_ReadInput(LCD_DATA_Port))
#define Delay8ms(ncount) Delay(100000*ncount)
#define u8 unsigned char
#define uchar unsigned char
#define u16 unsigned short int
//void LCD_ReadBusy(void);
void LCD_GPIOConfiguration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_LCDDataPort,ENABLE);
RCC_APB2PeriphClockCmd(RCC_LCDControlPort,ENABLE);
GPIO_InitStructure.GPIO_Pin=LCD_DATA_Pin;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_OD;
GPIO_Init(LCD_DATA_Port,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin=LCD_Control_pin;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
GPIO_Init(LCD_Control_Port,&GPIO_InitStructure);
}
void Delay(unsigned long t)
{
while(--t);
}
void lcd_wcmd(u8 cmd)
{
Delay(800);
LCD_RS0;
LCD_RW0;
GPIO_ResetBits(LCD_Control_Port,LCD_EN);
Delay(50);
LCD_WriteData(cmd);
Delay(800);
GPIO_SetBits(LCD_Control_Port,LCD_EN);
Delay(50);
GPIO_ResetBits(LCD_Control_Port,LCD_EN);
}
void lcd_wdat(u8 dat)
{
Delay(800);
LCD_RS1;
LCD_RW0;
GPIO_ResetBits(LCD_Control_Port,LCD_EN);
Delay(50);
LCD_WriteData(dat);
Delay(800);
GPIO_SetBits(LCD_Control_Port,LCD_EN);
Delay(50);
GPIO_ResetBits(LCD_Control_Port,LCD_EN);
}
void lcd_pos(uchar X,uchar Y)
{
uchar pos;
switch(X)
{
case 1: pos=0x80;break;
case 2: pos=0x90;break;
case 3: pos=0x88;break;
case 4: pos=0x98;break;
}
lcd_wcmd(pos+Y);
}
void lcd_pos_wstr(uchar X,uchar Y,uchar *str)
{
lcd_pos(X,Y);
while(*str)
{
lcd_wdat(*str);
str++;
}
}
void lcd_ws2tr(uchar n,uchar *str)
{
uchar j;
for(j=0;j<n;j++)
{
lcd_wdat(*str);
str++;
}
}
void lcd_init(void)
{
LCD_GPIOConfiguration();
GPIOC->ODR|=1<<3;
Delay8ms(10);
lcd_wcmd(0x30);
Delay8ms(10);
lcd_wcmd(0x30);
Delay8ms(5);
lcd_wcmd(0x0c);
Delay8ms(5);
lcd_wcmd(0x01);
Delay8ms(5);
lcd_wcmd(0x06);
Delay8ms(5);
}
void clr_screen(void)
{
lcd_wcmd(0x34);
Delay(10000);
lcd_wcmd(0x30);
Delay(10000);
lcd_wcmd(0x01);
Delay(10000);
}
#endif
|