微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > STM32 1602程序

STM32 1602程序

时间:09-10 来源:互联网 点击:

标 注:用到了 PD_0—7,给PO口(单片机板液晶数据口),PA0_2;

已在函数中将他们以寄存器形式配置,注踏出再次配置PD时

不应在配置这些口;

在主函数中需将PD,PA使能。

头函数:#include1602.h

函 数:在1602.h中有列举;

返回值:无;

用PD0_7给液晶数据,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

#includestm32f10x.h

#include1602.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=02;/

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;i16;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

}

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top