去网上或者自己写个显示时滚升钟的程序,只是你需要注枣备卜意使能端修改,
可以去技术论坛查找程序也可,或者直接去罗姆液晶厂家寻寻看还有时钟显示程序!!!
在mian函数里面雹漏斗写程序,具体主函数如下:#include "stm32f10x_lib.h"
int m=0
int n=0
#include "lcd.h"
char b[10]={'0','1','2','3','4','5','6','7','8','9'}
typedef enum {FAILED = 0, PASSED = !FAILED} TestStatus
vu32 ret
volatile TestStatus TestRx
void RCC_Configuration(void)
void GPIO_Configuration(void)
void NVIC_Configuration(void)
void CAN_Config(void)
TestStatus CAN_Polling(void)
TestStatus CAN_Interrupt(void)
void SysTick_Config(void)
void LcdShow_Init(void)
void Led_Config(void)
void Button_Config(void)
void Led_RW_ON(void)
void Led_RW_OFF(void)
void delay(void)
void delay()
{
int i,j
j=0
for (i=0i<0xfffffi++) j++
}
EXTI_InitTypeDef EXTI_InitStructure
int main(void)
{
char a[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P',
'Q'搜亏,'R','S','T','源磨U','V','W','X','Y','Z'}
#ifdef DEBUG
debug()
#endif
RCC_Configuration()
GPIO_Configuration()
NVIC_Configuration()
SysTick_Config()
LcdShow_Init()
Led_Config()
Button_Config()
GPIO_EXTILineConfig(GPIO_PortSourceGPIOD, GPIO_PinSource3)
EXTI_InitStructure.EXTI_Line = EXTI_Line3
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling
EXTI_InitStructure.EXTI_LineCmd = ENABLE
EXTI_Init(&EXTI_InitStructure)
GPIO_EXTILineConfig(GPIO_PortSourceGPIOD, GPIO_PinSource4)
EXTI_InitStructure.EXTI_Line = EXTI_Line4
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling
EXTI_InitStructure.EXTI_LineCmd = ENABLE
EXTI_Init(&EXTI_InitStructure)
while(1)
{
write_char(a+m,0,0)
n=a[m]
delay()
delay()
if(m==26)
{m=0}
}
}
void RCC_Configuration(void)
{
ErrorStatus HSEStartUpStatus
RCC_HSEConfig(RCC_HSE_ON)
HSEStartUpStatus = RCC_WaitForHSEStartUp()
if(HSEStartUpStatus == SUCCESS)
{
RCC_HCLKConfig(RCC_SYSCLK_Div1)
RCC_PCLK2Config(RCC_HCLK_Div1)
RCC_PCLK1Config(RCC_HCLK_Div2)
RCC_ADCCLKConfig(RCC_PCLK2_Div6)
FLASH_SetLatency(FLASH_Latency_2)
FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable)
RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9)
RCC_PLLCmd(ENABLE)
while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET)
{
}
RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK)
while(RCC_GetSYSCLKSource() != 0x08)
{
}
}
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB |RCC_APB2Periph_GPIOC
| RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE | RCC_APB2Periph_AFIO, ENABLE)
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE)
RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN, ENABLE)
}
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5 |GPIO_Pin_6 | GPIO_Pin_7
| GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz
GPIO_Init(GPIOC, &GPIO_InitStructure)
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_11 | GPIO_Pin_12 |
GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING
GPIO_Init(GPIOD, &GPIO_InitStructure)
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU
GPIO_Init(GPIOD, &GPIO_InitStructure)
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP
GPIO_Init(GPIOD, &GPIO_InitStructure)
GPIO_PinRemapConfig(GPIO_Remap2_CAN,ENABLE)
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz
GPIO_Init(GPIOE, &GPIO_InitStructure)
}
void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure
#ifdef VECT_TAB_RAM
NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0)
#else
NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0)
#endif
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2)
NVIC_InitStructure.NVIC_IRQChannel=TIM2_IRQChannel
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE
NVIC_Init(&NVIC_InitStructure)
NVIC_InitStructure.NVIC_IRQChannel = EXTI3_IRQChannel
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE
NVIC_Init(&NVIC_InitStructure)
NVIC_InitStructure.NVIC_IRQChannel = EXTI4_IRQChannel
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE
NVIC_Init(&NVIC_InitStructure)
NVIC_SystemHandlerPriorityConfig(SystemHandler_SysTick, 2, 0)
}
void LcdShow_Init(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure
TIM_OCInitTypeDef TIM_OCInitStructure
TIM_TimeBaseStructure.TIM_Period = 8000
TIM_TimeBaseStructure.TIM_Prescaler = 17
TIM_TimeBaseStructure.TIM_ClockDivision = 0x0
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up
TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure)
TIM_ARRPreloadConfig(TIM2,DISABLE)
TIM_UpdateRequestConfig(TIM2,TIM_UpdateSource_Regular)
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Timing
TIM_OCInitStructure.TIM_Channel = TIM_Channel_1
TIM_OCInitStructure.TIM_Pulse = 4000
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High
TIM_OCInit(TIM2, &TIM_OCInitStructure)
TIM_OC1PreloadConfig(TIM2, TIM_OCPreload_Disable)
TIM_ITConfig(TIM2, TIM_IT_CC1 | TIM_IT_Update, ENABLE)
TIM_Cmd(TIM2, ENABLE)
}
void SysTick_Config(void)
{
SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK)
SysTick_SetReload(720000)
SysTick_ITConfig(ENABLE)
SysTick_CounterCmd(SysTick_Counter_Enable)
}
void Button_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD, ENABLE)
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_4
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz
GPIO_Init(GPIOD, &GPIO_InitStructure)
}
void Led_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE)
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_4 | GPIO_Pin_5
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz
GPIO_Init(GPIOC, &GPIO_InitStructure)
}
void Led_RW_ON(void)
{
m++
}
void Led_RW_OFF(void)
{
int i,j
i=n/10
j=n%10
write_char(b+i,0,2)
write_char(b+j,0,3)
}
#ifdef DEBUG
void assert_failed(u8* file, u32 line)
{
while (1)
{
}
}
#endif
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)