STM32 1602程序
標(biāo) 注:用到了 PD_0—7,給PO口(單片機(jī)板液晶數(shù)據(jù)口),PA0_2;
已在函數(shù)中將他們以寄存器形式配置,注踏出再次配置PD時(shí)
不應(yīng)在配置這些口;
在主函數(shù)中需將PD,PA使能。
頭函數(shù):#include"1602.h"
函 數(shù):在1602.h中有列舉;
返回值:無(wú);
用PD0_7給液晶數(shù)據(jù),PA0_2位控制為依次rs,rw,en;
#ifndef __1602_H
#define __1602_H
#include "stm32f10x.h"
void write1602_com(u8 com);
void write1602_dat(u8 dat);
void lcd1602_init(void);
void write1602_Achar(u8 hang,u8 numadd,u8 x);
void write1602_string(u8 hang,u8 numadd,u8 *p);
#endif
#include"stm32f10x.h"
#include"1602.h"
//sbit rs=P2^5;//gpioa_0
//sbit rw=P2^6;//gpioa_1
//sbit en=P2^7;//gpioa_2
void Delayms(unsigned short time)//nms
{
unsigned short i, j;
for(; time > 0; time--){
for(j = 0; j < 10; j++){
for(i = 0; i < 1000; i++);
}
}
}
void write1602_com(u8 com)
{
GPIOD->ODR&=0xff00;//??
GPIOA->ODR&=0xfffb;//GPIOA->ODR&=0<<2;/
void RCC_Configuration(void);
void GPIO_Configuration(void);
void NVIC_Configuration(void);
u8 table[]="2010-4-30";
void Delay(unsigned short time)//nms
{
unsigned short i, j;
for(; time > 0; time--){
for(j = 0; j < 10; j++){
for(i = 0; i < 1000; i++);
}
}
}
int main(void)
{
u8 i;
RCC_Configuration();
NVIC_Configuration();
GPIO_Configuration();
lcd1602_init();
while (1)
{
//i=Keyscan();
//Led(i);
write1602_string(1,17,table);
for(i=0;i<16;i++)
{
write1602_com(0x18);
Delay(200);
}
}
}
void RCC_Configuration(void)
{
RCC_DeInit();
RCC_HSEConfig(RCC_HSE_ON);
HSEStartUpStatus = RCC_WaitForHSEStartUp();
if(HSEStartUpStatus == SUCCESS)
{
FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
FLASH_SetLatency(FLASH_Latency_2);
RCC_HCLKConfig(RCC_SYSCLK_Div1);
RCC_PCLK2Config(RCC_HCLK_Div1);
RCC_PCLK1Config(RCC_HCLK_Div2);
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_GPIOC|RCC_APB2Periph_GPIOA| RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOB
| RCC_APB2Periph_AFIO, ENABLE);
}
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin =GPIO_Pin_All;
GPIO_InitStructure.GPIO_Speed =GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode =GPIO_Mode_Out_PP;
GPIO_Init(GPIOB, &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
}