直接上代码:lol
main函数/*---------------------------------------------------------------------------------------------------------*/
/* */
/* Copyright(c) 2011 Nuvoton Technology Corp. All rights reserved. */
/* */
/*---------------------------------------------------------------------------------------------------------*/
#include "includes.h" //包含所需的头文件
/*************************************************************************************
** Function name: main
** Descriptions: LCM + 流水灯
** input parameters: 无
** output parameters: 无
** Returned value: 无
*************************************************************************************/
int main (void)
{
Set_System();
LCMTextOut( 1,"祝菜农老师的学习");
LCMTextOut( 17,"菜地越办越好越办");
LCMTextOut(9,"越红火!");
while(1)
{
DrvGPIO_SetBit(E_GPA,5);
DrvGPIO_ClrBit(E_GPA,2);
delay_ms(100);
DrvGPIO_SetBit(E_GPA,2);
DrvGPIO_ClrBit(E_GPA,3);
delay_ms(100);
DrvGPIO_SetBit(E_GPA,3);
DrvGPIO_ClrBit(E_GPA,4);
delay_ms(100);
DrvGPIO_SetBit(E_GPA,4);
DrvGPIO_ClrBit(E_GPA,5);
delay_ms(100);
}
}
hw_config.c函数
#include "includes.h" //包含所需的头文件
/*************************************************************************************
** Function name: Set_System
** Descriptions: 系统
** input parameters: 无
** output parameters: 无
** Returned value: 无
*************************************************************************************/
void Set_System(void)
{
RCC_Configuration(); //配置系统时钟
GPIO_Configuration(); //配置GPIO
LCMInit(); //初始化液晶
}
/*************************************************************************************
** Function name: RCC_Configuration
** Descriptions: 系统时钟源设置
** input parameters: none
** output parameters: none
** Returned value: none
*************************************************************************************/
void RCC_Configuration(void)
{
UNLOCKREG(); // 对写保护位操作时 需要一次向0x50000 0100写入 0x59,0x16,0x88,
DrvSYS_SetOscCtrl(E_SYS_XTL12M, 1);//与其 SYSCLK->PWRCON.XTL12M_EN = 1; 等同
// PWRCON寄存器(这些寄存器在上电复位到用户解锁定之前是锁定的)除了 BIT[6]位其他位都受写保护
// 解除这些需要向 0x50000 0100写入 0x59,0x16,0x88,
// 令PWRCON寄存器的BITP[0]为1(即设定12M外部晶振)
delay_ms(100); //while (DrvSYS_GetChipClockSourceStatus(E_SYS_XTL12M) != 1);//等待外部12MHZ晶振就绪
LOCKREG(); // 向“0x5000_0100”写入任何值,就可以重锁保护寄存器
}
/*************************************************************************************
** Function name: GPIO_Configuration
** Descriptions: 端口配置
** input parameters: none
** output parameters: none
** Returned value: none
*************************************************************************************/
void GPIO_Configuration()
{
DrvGPIO_Open( E_GPA, 2, E_IO_OUTPUT ); //DB0~DB7
DrvGPIO_Open( E_GPA, 3, E_IO_OUTPUT );
DrvGPIO_Open( E_GPA, 4, E_IO_OUTPUT );
DrvGPIO_Open( E_GPA, 5, E_IO_OUTPUT );
DrvGPIO_Open( E_GPA, 6, E_IO_OUTPUT );
DrvGPIO_Open( E_GPA, 7, E_IO_OUTPUT );
DrvGPIO_Open( E_GPA, 8, E_IO_OUTPUT );
DrvGPIO_Open( E_GPA, 9, E_IO_OUTPUT );
DrvGPIO_Open( E_GPC, 14, E_IO_OUTPUT ); //RS
DrvGPIO_Open( E_GPC, 15, E_IO_OUTPUT ); //R/W
DrvGPIO_Open( E_GPC, 6, E_IO_OUTPUT ); //EN
}
/*************************************************************************************
** Function name: delay_ms
** Descriptions: 1ms(晶振为12MHZ)延时子程序
** input parameters: count
** output parameters: 无
** Returned value: 无
*************************************************************************************/
void delay_ms(uint32_t count)
{
uint32_t i,j;
for(i=count;i>0;i--)
for(j=2395;j>0;j--);
}
hw_config.h头文件
#ifndef __HW_CONFIG_H__
#define __HW_CONFIG_H__
void Set_System(void);
void RCC_Configuration(void);
void GPIO_Configuration(void);
void delay_ms(uint32_t count);
#endif
lcm_128_64.c函数
#include "includes.h" //包含所需的头文件
//Write Command
void WriteCommandLCM(uint32_t in_com)
{
int32_t com;
com = in_com;
com <<= 2;
DrvGPIO_ClrBit(E_GPC,15);//LCD_RW = 0;
DrvGPIO_ClrBit(E_GPC,14);//LCD_RS = 0;
DrvGPIO_SetBit(E_GPC,6); //LCD_EN = 1;
delay_ms(1);
GPIOA->DOUT = com;
delay_ms(1);
DrvGPIO_ClrBit(E_GPC,6); //LCD_EN = 0;
DrvGPIO_SetBit(E_GPC,14);//LCD_RS = 1;
DrvGPIO_SetBit(E_GPC,15);//LCD_RW = 1;
delay_ms(3);
}
//Write Data
void WriteDataLCM(uint32_t in_data)
{
int32_t data;
data = in_data;
data <<= 2;
DrvGPIO_SetBit(E_GPC,14);//LCD_RS = 1;
DrvGPIO_ClrBit(E_GPC,15);//LCD_RW = 0;
DrvGPIO_SetBit(E_GPC,6); //LCD_EN = 1;
delay_ms(1);
GPIOA->DOUT = data;
delay_ms(1);
DrvGPIO_ClrBit(E_GPC,6); //LCD_EN = 0;
DrvGPIO_SetBit(E_GPC,14);//LCD_RS = 1;
DrvGPIO_SetBit(E_GPC,15);//LCD_RW = 1;
delay_ms(3);
}
//Display Char String
void LCMTextOut(uint8_t address,uint8_t *LCMCharArray)
{
address--;
WriteCommandLCM(0x80+address);
while(*LCMCharArray)
{
WriteDataLCM(*LCMCharArray);
LCMCharArray++;
}
}
//Init LCM
void LCMInit(void)
{
WriteCommandLCM(0x38); //设接口数据位数(DL),显示行数(L),及字型(F)
delay_ms(10);
WriteCommandLCM(0x01); //清屏指令
delay_ms(10);
WriteCommandLCM(0x0C); //设整体显示开关(D),光标开关关(C),及光标位的字符不闪耀(B)
delay_ms(10);
WriteCommandLCM(0x06); //7设光标移动方向并指定整体显示是否移动
delay_ms(10);
WriteCommandLCM(0x80); //设DDRAM地址,设置后DDRAM数据被发送和接收
}
lcm_128_64.h头文件
#ifndef __LCM_128_64_H__
#define __LCM_128_64_H__
void WriteCommandLCM(uint32_t data);
void WriteDataLCM(uint32_t in_data);
void LCMTextOut(uint8_t address,uint8_t *LCMCharArray);
void LCMInit(void);
#endif
includes.h头文件
#include <stdio.h>
#include "NUC1xx.h"
#include "variables.h"
#include "hw_config.h"
#include "lcm_128_64.h"
#include "Driver\DrvGPIO.h"
#include "Driver\DrvSYS.h"
截图
工程
Li-LCM.rar
(889.24 KB)
|