程序已在面包版上通过,复位后闪烁 至于要什么,怎样显示,请参考zlg7289b 的技术手册
#include "stm32f10x_lib.h"
void RCC_Configuration(void); void GPIO_Configuration(void); void NVIC_Configuration(void); void SysTick_Config(void); void Led_RW_ON(void); void Led_RW_OFF(void); void Led_RE_ON(void); void Led_RE_OFF(void); void delay(void); void delay_long(void); void send_byte(u8 out_byte); void Write_ZLG7289B(u8 cmd ,u8 data);
int main(void) { #ifdef DEBUG debug(); #endif RCC_Configuration(); GPIO_Configuration(); NVIC_Configuration(); SysTick_Config(); delay(); delay(); delay(); send_byte(0xA4); delay(); delay(); send_byte(0xBF); while (1) { Led_RW_ON(); delay(); Led_RW_OFF(); delay(); Led_RW_ON(); delay(); Led_RW_OFF(); delay(); Led_RW_ON(); delay(); Led_RW_OFF(); delay(); } }
void RCC_Configuration(void) { ErrorStatus HSEStartUpStatus;
/* RCC system reset(for debug purpose) */ RCC_DeInit();
/* Enable HSE */ RCC_HSEConfig(RCC_HSE_ON);
/* Wait till HSE is ready */ HSEStartUpStatus = RCC_WaitForHSEStartUp();
if(HSEStartUpStatus == SUCCESS) { /* HCLK = SYSCLK */ RCC_HCLKConfig(RCC_SYSCLK_Div1);
/* PCLK2 = HCLK */ RCC_PCLK2Config(RCC_HCLK_Div1);
/* PCLK1 = HCLK/2 */ RCC_PCLK1Config(RCC_HCLK_Div2);
/* ADCCLK = PCLK2/6 */ RCC_ADCCLKConfig(RCC_PCLK2_Div6);
/* Flash 2 wait state */ FLASH_SetLatency(FLASH_Latency_2);
/* Enable Prefetch Buffer */ FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
/* PLLCLK = 4MHz * 9 = 36 MHz */ RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);
/* Enable PLL */ RCC_PLLCmd(ENABLE);
/* Wait till PLL is ready */ while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET) { }
/* Select PLL as system clock source */ RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
/* Wait till PLL is used as system clock source */ while(RCC_GetSYSCLKSource() != 0x08) { } }
/* Enable GPIOA, GPIOB, GPIOC, GPIOD, GPIOE and AFIO clocks */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB |RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE | RCC_APB2Periph_AFIO, ENABLE);
/* TIM2 clocks enable */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
/* CAN Periph clock enable */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN, ENABLE); }
/******************************************************************************* * Function Name : GPIO_Configuration * Description : Configures the different GPIO ports. * Input : None * Output : None * Return : None *******************************************************************************/ void GPIO_Configuration(void) { GPIO_InitTypeDef GPIO_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5 |GPIO_Pin_6 | GPIO_Pin_7; //ZLG7289B_CS ~ PC04 //ZLG7289B_CLK ~ PC05 //ZLG7289B_DIO ~ PC06 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOC, &GPIO_InitStructure); }
/******************************************************************************* * Function Name : NVIC_Configuration * Description : Configures the NVIC and Vector Table base address. * Input : None * Output : None * Return : None *******************************************************************************/ void NVIC_Configuration(void) { NVIC_InitTypeDef NVIC_InitStructure;
#ifdef VECT_TAB_RAM /* Set the Vector Table base location at 0x20000000 */ NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0); #else /* VECT_TAB_FLASH */ /* Set the Vector Table base location at 0x08000000 */ NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0); #endif
/* Configure the Priority Group to 2 bits */ NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
/* enabling interrupt */ 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);
/* Enable the EXTI3 Interrupt on PD.3 */ NVIC_InitStructure.NVIC_IRQChannel = EXTI3_IRQChannel; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure);
/* Enable the EXTI4 Interrupt on PD.4 */ NVIC_InitStructure.NVIC_IRQChannel = EXTI4_IRQChannel; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure);
/* Configure the SysTick handler priority */ NVIC_SystemHandlerPriorityConfig(SystemHandler_SysTick, 2, 0); }
void SysTick_Config(void) { /* Configure HCLK clock as SysTick clock source */ SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK);
/* SysTick interrupt each 100 Hz with HCLK equal to 72MHz */ SysTick_SetReload(720000);
/* Enable the SysTick Interrupt */ SysTick_ITConfig(ENABLE);
/* Enable the SysTick Counter */ SysTick_CounterCmd(SysTick_Counter_Enable); }
void delay() { int i; for (i=0; i<0xfffff; i++); }
void delay_long() { u16 j; for(j=0;j<800;j++); }
void send_byte(u8 out_byte) //8位写指令 { u8 i; GPIO_ResetBits(GPIOC, GPIO_Pin_6); delay_long(); for(i=0;i<8;i++) { if (out_byte&0x80) GPIO_SetBits(GPIOC, GPIO_Pin_4); else GPIO_ResetBits(GPIOC, GPIO_Pin_4); GPIO_SetBits(GPIOC, GPIO_Pin_5); delay_long(); GPIO_ResetBits(GPIOC, GPIO_Pin_5); delay_long(); out_byte=out_byte*2; } GPIO_SetBits(GPIOC, GPIO_Pin_6); }
void Write_ZLG7289B(u8 cmd ,u8 data) //写8位指令,写8为数据 { u8 i; GPIO_ResetBits(GPIOC, GPIO_Pin_6); delay_long(); for(i=0;i<8;i++) { if (cmd&0x80) GPIO_SetBits(GPIOC, GPIO_Pin_4); else GPIO_ResetBits(GPIOC, GPIO_Pin_4); GPIO_SetBits(GPIOC, GPIO_Pin_5); delay_long(); GPIO_ResetBits(GPIOC, GPIO_Pin_5); delay_long(); cmd=cmd*2; } delay_long(); for(i=0;i<8;i++) { if (data&0x80) GPIO_SetBits(GPIOC, GPIO_Pin_4); else GPIO_ResetBits(GPIOC, GPIO_Pin_4); GPIO_SetBits(GPIOC, GPIO_Pin_5); delay_long(); GPIO_ResetBits(GPIOC, GPIO_Pin_5); delay_long(); data=data*2; } GPIO_SetBits(GPIOC, GPIO_Pin_6);
}
void Led_RW_ON(void) { GPIO_SetBits(GPIOC, GPIO_Pin_7 ); }
void Led_RW_OFF(void) { GPIO_ResetBits(GPIOC,GPIO_Pin_7 ); }
#ifdef DEBUG /******************************************************************************* * Function Name : assert_failed * Description : Reports the name of the source file and the source line number * where the assert error has occurred. * Input : - file: pointer to the source file name * - line: assert error line source number * Output : None * Return : None *******************************************************************************/ void assert_failed(u8* file, u32 line) { /* User can add his own implementation to report the file name and line number, ex: printf("Wrong parameters value: file %s on line %d
", file, line) */
/* Infinite loop */ while (1) { } } #endif
|
|