/******************** (C) COPYRIGHT 2008 STMicroelectronics ********************
* File Name : main.c
* Author : MCD Application Team
* Version : V2.0.3
* Date : 09/22/2008
* Description : Main program body
********************************************************************************
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*******************************************************************************/
/* Includes ------------------------------------------------------------------*/
#include "stm32f10x_lib.h"
#define uint unsigned int
#define uchar unsigned char
#define RSH GPIO_SetBits(GPIOA,GPIO_Pin_0)
#define RSL GPIO_ResetBits(GPIOA,GPIO_Pin_0)
#define RWH GPIO_SetBits(GPIOA,GPIO_Pin_1)
#define RWL GPIO_ResetBits(GPIOA,GPIO_Pin_1)
#define ENH GPIO_SetBits(GPIOA,GPIO_Pin_2)
#define ENL GPIO_ResetBits(GPIOA,GPIO_Pin_2)
#define CS1H GPIO_SetBits(GPIOA,GPIO_Pin_3)
#define CS1L GPIO_ResetBits(GPIOA,GPIO_Pin_3)
#define CS2H GPIO_SetBits(GPIOA,GPIO_Pin_4)
#define CS2L GPIO_ResetBits(GPIOA,GPIO_Pin_4)
void RCC_Configuration(void);
void NVIC_Configuration(void);
void GPIO_Configuration(void);
void Delay();
uchar table[][16]=
{
///-- 文字: 爱
//-- 宋体12;
0x00,0x40,0xB2,0x96,0x9A,0x92,0xF6,0x9A,0x93,0x91,0x99,0x97,0x91,0x90,0x30,0x00,
0x40,0x20,0xA0,0x90,0x4C,0x47,0x2A,0x2A,0x12,0x1A,0x26,0x22,0x40,0xC0,0x40,0x00,
};
void Write_cmd_left(uchar cmd)
{
RSL;
RWL;
CS1H;
GPIO_Write(GPIOF,cmd);
ENL;
Delay(300);
ENH;
Delay(300);
ENL;
Delay(300);
CS1L;
}
void Write_cmd_right(uchar cmd)
{
RSL;
RWL;
CS2H;
GPIO_Write(GPIOF,cmd);
ENL;
Delay(300);
ENH;
Delay(300);
ENL;
Delay(300);
CS2L;
}
void Write_data_left(uchar data)
{
RSH;
RWL;
CS1H;
GPIO_Write(GPIOF,data);
ENL;
Delay(300);
ENH;
Delay(300);
ENL;
Delay(300);
CS1L;
}
void Write_data_right(uchar data)
{
RSH;
RWL;
CS2H;
GPIO_Write(GPIOF,data);
ENL;
Delay(300);
ENH;
Delay(300);
ENL;
Delay(300);
CS1L;
}
void led_disp(uchar*p,uchar lr)
{
uchar i,ch;
if(lr=='L')
{
for(i=0;i<8;i++)
{
ch=*p;
p++;
Write_data_left(ch);
}
}
if(lr=='R')
{
for(i=0;i<8;i++)
{
ch=*p;
p++;
Write_data_right(ch);
}
}
}
void clear()
{
uchar i,j,disp_page;
for(i=0;i<8;i++)
{
disp_page=0xb8+i;
Write_cmd_left(disp_page);
Write_cmd_left(0x40);
for(j=0;j<64;j++)
Write_data_left(0x00);
}
for(i=0;i<8;i++)
{
disp_page=0xb8+i;
Write_cmd_right(disp_page);
Write_cmd_right(0x40);
for(j=0;j<64;j++)
Write_data_right(0x00);
}
}
void init()
{
Write_cmd_left(0x3e);
Write_cmd_right(0x3e);
Write_cmd_left(0x3f);
Write_cmd_right(0x3f);
Write_cmd_left(0xc0);
Write_cmd_right(0xc0);
}
int main(void)
{
/* Infinite loop */
RCC_Configuration();
NVIC_Configuration();
GPIO_Configuration();
clear();
Delay(300);
init();
Delay(300);
while (1)
{
Write_cmd_left(0xb8);
Write_cmd_left(0x40);
for(uchar i=0;i<4;i++)
led_disp(table[i],'L');
}
}
/******************************************************************************
*Function Name :RCC_Configuration.
*Descriprion :configures the different system clocks.
*Input :None
*Output :None
*Return :None
*******************************************************************************/
void RCC_Configuration(void)
{
ErrorStatus HSEStartUpStatus;
/*RCC system reset(for debug purpose)*/
RCC_DeInit();//将外设RCC寄存器重设为缺省值
/*Enable HSE 打开外部时钟*/
RCC_HSEConfig(RCC_HSE_ON);
/*Wait till HSE is read */
HSEStartUpStatus = RCC_WaitForHSEStartUp();//等待HSE起振
if(HSEStartUpStatus==SUCCESS)//起振成功
{
/*Enable PrefetchBuffer 打开flash的预存储功能*/
FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
/*FLASH 2 Wait state*/
FLASH_SetLatency(FLASH_Latency_2);//设置代码延时值
/*HCLK=syclk*/
RCC_HCLKConfig(RCC_SYSCLK_Div1);//设置AHB时钟等于系统时钟
/*PCLK2=HCLK*/
RCC_PCLK2Config(RCC_HCLK_Div1);
/*RCLK1=HCLK*/
RCC_PCLK1Config(RCC_HCLK_Div2);
/*PLLCLK=8MHZ*9=72MHZ*/
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 used as system clock source*/
while(RCC_GetSYSCLKSource() !=0x08)
{
}
/*打开相应的外部时钟:GPIOF*/
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOF, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
}
else
{
}
}
/******************************************************************************
*Function Name :NVIC_Configuration.
*Descriprion :configures Vector Table base location.
*Input :None
*Output :None
*Return :None
*******************************************************************************/
void NVIC_Configuration(void)
{
#ifdef VECT_TAB_RAM
/*Set the vector table base location at 0x20000000*/
NVIC_SetVectorTable(NVIC_VectTab_RAM,0X0);
#else
/*Set the vector table base location at 0x20000000*/
NVIC_SetVectorTable(NVIC_VectTab_FLASH,0x0);
#endif
}
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_All;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //设置GPIO的工作状态
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //设置GPIO的速度
GPIO_Init(GPIOF, &GPIO_InitStructure);
GPIO_Init(GPIOA, &GPIO_InitStructure);
}
/******************************************************************************
延时函数
******************************************************************************/
void Delay(vu32 nCount)
{
for(; nCount != 0; nCount--);
} |
|