打印

新手的小程序,欢迎拍砖和扔**蛋!!!

[复制链接]
2055|7
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
顺德华安|  楼主 | 2008-2-19 15:34 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
以下小程序在EK-STM32实验板上通过.顺便那位高手
推荐一块最小12位的Led显示芯片,2块zlg7290c成本太高
最好系内建晶震和I2C接口,谢谢!!

#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);

int main(void)
{
#ifdef DEBUG
  debug();
#endif
  RCC_Configuration();
  GPIO_Configuration();
  NVIC_Configuration();
  SysTick_Config();
  while (1)
  {
   Led_RW_ON();
   Led_RE_ON();
   delay();
   Led_RW_OFF();
   Led_RE_OFF();
   delay();
   Led_RW_ON();
   Led_RE_ON();
   delay();
   Led_RW_OFF();
   Led_RE_OFF();
   delay();
   Led_RW_ON();
   Led_RE_OFF();
   delay();
   Led_RW_OFF();
   Led_RE_ON();
   delay();
   Led_RW_ON();
   Led_RE_OFF();
   delay();
   Led_RW_OFF();
   Led_RE_ON();
   delay();
   Led_RW_ON();
   Led_RE_OFF();
   delay();
   Led_RW_OFF();
   Led_RE_ON();
   delay();
   Led_RW_ON();
   Led_RE_OFF();
   delay();
   Led_RW_OFF();
   Led_RE_ON();
   delay();
   Led_RW_ON();
   Led_RE_ON();
   delay();
   Led_RW_OFF();
   Led_RE_OFF();
   delay();
   Led_RW_ON();
   Led_RE_ON();
   delay();
   Led_RW_OFF();
   Led_RE_OFF();
   delay();
   Led_RW_ON();
   Led_RE_ON();
   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; 
  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 Led_RW_ON(void)
{
  GPIO_SetBits(GPIOC, GPIO_Pin_6 | GPIO_Pin_7 );
}

void Led_RW_OFF(void)
{
  GPIO_ResetBits(GPIOC, GPIO_Pin_6 | GPIO_Pin_7 );
}
void Led_RE_ON(void)
{
  GPIO_SetBits(GPIOC, GPIO_Pin_4 | GPIO_Pin_5 );
}

void Led_RE_OFF(void)
{
  GPIO_ResetBits(GPIOC, GPIO_Pin_4 | GPIO_Pin_5 );
}
#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

/******************* (C) COPYRIGHT 2007 STMicroelectronics *****END OF FILE****/
沙发
顺德华安|  楼主 | 2008-2-19 16:51 | 只看该作者

zlg7289B的显示程序正在草稿

zlg7289B的显示程序正在草稿,电路正在
面包板上搭起来,有空马上搞程序,通过后会马上
上传给各位指点,欢迎扔烂**蛋
你的批评等于给我宝贵意见!!!

使用特权

评论回复
板凳
jessemok| | 2008-2-20 12:27 | 只看该作者

板凳

路过,等有时间再给你拍拍。

使用特权

评论回复
地板
太空穿梭机| | 2008-2-20 12:42 | 只看该作者

楼主的程序完全正确

使用特权

评论回复
5
mohanwei| | 2008-2-20 14:02 | 只看该作者

LED……用164,595也不错

使用特权

评论回复
6
yjf1979yjf| | 2008-2-22 17:20 | 只看该作者

你不觉的你的代码叫人看起来很头疼么

明显很多重复 可以写到一个函数里 

使用特权

评论回复
7
niu9911| | 2008-2-22 18:14 | 只看该作者

支持6楼

  while (1)
  {
   Led_RW_ON();
   Led_RE_ON();
   delay();
   Led_RW_OFF();
   Led_RE_OFF();
   delay();
   Led_RW_ON();
   Led_RE_ON();
   delay();
   Led_RW_OFF();
   Led_RE_OFF();
   delay();
   Led_RW_ON();
   Led_RE_OFF();
   delay();
   Led_RW_OFF();
   Led_RE_ON();
   delay();
   Led_RW_ON();
   Led_RE_OFF();
   delay();
   Led_RW_OFF();
   Led_RE_ON();
   delay();
   Led_RW_ON();
   Led_RE_OFF();
   delay();
   Led_RW_OFF();
   Led_RE_ON();
   delay();
   Led_RW_ON();
   Led_RE_OFF();
   delay();
   Led_RW_OFF();
   Led_RE_ON();
   delay();
   Led_RW_ON();
   Led_RE_ON();
   delay();
   Led_RW_OFF();
   Led_RE_OFF();
   delay();
   Led_RW_ON();
   Led_RE_ON();
   delay();
   Led_RW_OFF();
   Led_RE_OFF();
   delay();
   Led_RW_ON();
   Led_RE_ON();
   delay();
  }
}
这一个WHILE看起来太不爽了!

使用特权

评论回复
8
hotpower| | 2008-2-22 18:16 | 只看该作者

哈哈~~~晕呀~~~

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

18

主题

58

帖子

0

粉丝