大学生
最后登录1970-1-1
在线时间 小时
注册时间2013-5-27
|
/******************** (C) COPYRIGHT 2012 WildFire Team ***************************
* 文件名 :led.c
* 描述 :led 应用函数库
* 实验平台:野火STM32开发板
**********************************************************************************/
#include "led.h"
/*
* 函数名:_1602_GPIO_Config
* 描述 :配置LED用到的I/O口
* 输入 :无
* 输出 :无
*/
void _1602_GPIO_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;//PA1,3,7
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All; //PA7-15
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
}
//延时nus
void delay_nus(unsigned long n)
{
unsigned long j;
while(n--)
{ j=9;
while(j--);
}
}
//延时nms
void DelayMs(unsigned char t)
{
while(t--)
delay_nus(1111);
}
//命令初始化
void LCD_write_com(unsigned char com)
{
E(0);
delay_nus(1);
RS(0);
delay_nus(1);
RW(0);
delay_nus(1);
GPIO_Write(GPIOB,(com<<8) & 0xff00);
delay_nus(500);
E(1);
DelayMs(1);
E(0);
delay_nus(100);
}
//写入数据
void LCD_write_data(unsigned char Data)
{
E(0);
delay_nus(10);
RS(1);
delay_nus(10);
RW(0);
delay_nus(10);
GPIO_Write(GPIOB,(Data<<8) & 0xff00);
delay_nus(500);
E(1);
DelayMs(1);
E(0);
delay_nus(100);
}
//清屏
void LCD_Clear(void)
{ LCD_write_com(0x01);
DelayMs(5);
}
//写入字符串函数
void LCD_write_string(unsigned char x,unsigned char y,unsigned char *s)
{ if (y == 0)
{
LCD_write_com(0x80+x);
}
else
{
LCD_write_com(0xc0+x);
}
while (*s!='\0')
{
LCD_write_data(*s);
s++;
delay_nus(500);
}
}
//写入字符函数
void LCD_write_char(unsigned char x,unsigned char y,unsigned char data)
{
if (y == 0)
{
LCD_write_com(0x80+x);
}
else
{
LCD_write_com(0xc0+x);
}
LCD_write_data(data);
delay_nus(500);
}
void LCD_INIT(void)
{
DelayMs(15);
LCD_write_com(0x38); //显示模式
DelayMs(5);
LCD_write_com(0x38);
DelayMs(5);
LCD_write_com(0x38);
DelayMs(5);
LCD_write_com(0x38);
DelayMs(5);
LCD_write_com(0x08); //显示关闭
DelayMs(5);
LCD_write_com(0x01); //显示清屏
DelayMs(5);
LCD_write_com(0x06); //显示光标移动设置
DelayMs(5);
LCD_write_com(0x0c); //显示打开及光标设置
DelayMs(5);
}
/******************* (C) COPYRIGHT 2012 WildFire Team *****END OF FILE************/
|
|