本 LED 点阵屏和 LDC 屏幕的显示,我利用了实验室,采集了电压模拟量,实现了 A/D 转换,在 LED 点阵屏动态显示出了电压值,并滚动显示了实验者的学号和姓名;在 LED 显示的同时,在 LCD 屏上同步显示了采样数据。通过这次嵌入式应用课程设计的实践,我了解了 S3C2410 的芯片结构和特点,掌握了 I/O 接口编程方法,理解了键盘和 LED 点阵屏的接口原理,掌握了 LED 点阵屏控制的编程方法,并实现了键盘控制 LED 点阵屏的显示,为之后的嵌入式开发的深入学习打下了基础。
这个项目是我大三写的,现在回顾已经非常粗糙,分享出来一方面希望可以帮助初学者,另一方面希望能让同学们可以从目前大学中普遍毫无价值的形式主义作业中解脱出来,更加高效地学习优质计算机知识和主流编程技术,一起发扬开源精神,感受互联网技术的美好愿景。
互联网开源精神需要大家一起互相交流学习,互相支持奉献。欢迎大家与我友好交流。
加我 QQ 好友获取所有项目源码和项目文档,感谢大家的支持!
实验采用的是液晶屏幕是(LCD),按显示原理可以分为两种:STN 和 TFT。
STN 液晶显示屏,使用的是 XY 轴交叉的单纯电极驱动方式,即 X、Y 轴由垂直与水平方向的驱动电极构成,水平方向驱动电压控制显示部分为亮或暗,垂直方向的电极则负责驱动液晶分子的显示。STN 液晶显示屏加上彩色滤光片,并将单色显示矩阵中的每一像素分成三个子像素,分别通过彩色滤光片显示红、绿、蓝三原色,也可以显示出色彩。单色液晶屏及灰度液晶屏都是 STN 液晶屏。
TFT 彩色液晶屏:
液晶屏的显示要求设计专门的驱动与显示控制电路。驱动电路包括提供液晶屏的驱动电源和液晶分子偏置电压,以及液晶显示屏的驱动逻辑。显示控制部分可由专门的硬件电路组成,也可以采用集成电路(IC)模块,比如 EPSON 的视频驱动器等;还可以使用处理器外围 LCD 控制模块。实 验板的驱动与显示系统包括 S3C2410X 片内外设 LCD 控制器、液晶显示屏的驱动逻辑以及外围驱动电路。
S3C2410X LCD 控制器:
LCD 控制器特点:
S3C2410X 处理器集成了 LCD 控制器,主要功能是 S3C2410X LCD 控制器用于传输显示数据和 产生控制信号。它并支持屏幕水平和垂直滚动显示。数据的传送采用 DMA(直接内存访问)方式, 以达到最小的延迟。它可以支持多种液晶屏:
STN LCD:
支持 3 种类型的扫描方式:4 位单扫描,4 位双扫描和 8 位单扫描。
支持单色,4 级灰度和 16 级灰度显示。
支持 256 色和 4096 色彩色 STN LCD。
支持多种屏幕大小。
典型的实际屏幕大小是:640× 480,320× 240,160× 160 和其它最大虚拟屏幕占内存大小为 4M 字节 256 色模式下最大虚拟屏幕大小:4096× 1024, 2048× 2048, 1024× 4096 和其它。
TFT LCD:
支持 1,2,4 或 8bpp 彩色调色显示。
支持 16bpp 和 24bpp 非调色真彩显示。
在 24bpp 模式下,最多支持 16M 种颜色。
支持多种屏幕大小。
典型的实际屏幕大小是: 640× 480, 320× 240, 160× 160 和其它。
最大虚拟屏幕占内存大小为 4M 字节。
64K 色模式下最大虚拟屏幕大小:2048× 1024 和其它 LCD 控制器内部结构 LCD 控制器主要提供液晶屏显示数据的传送、时钟和各种信号的产生与控制功能。
ADC 转化原理:
实验中需要在计算机中处理各种检测的信号,就需要先将模拟信息转化为数字信息,这就是 A/D 转换。A/D 装换的一般过程就是取样、保持、量化和编码这四个步骤。一般取样和保持主要由采样保持器来完成,而量化编码就由 A/D 转换器完成。
S3C2410x 处理器的 A/D 转换,处理器内部集成了采用近似比较算法(计数式)的 8 路 10 位 ADC,集成零比较器,内部产生比较时钟信号;支持软件使能休眠模式,以减少电源损耗。在处理器中的 A/D 转换器的使用,需要使用到两个寄存器即 ADC 控制寄存器 ADCCON、ADC 数据寄存器。
串口通信原理:
在此次实验中需要使用到串口的通讯,而在 S3C2410X UART 单元提供三个独立的异步串行通信接口,皆可工作于中断和 DMA 模式。使用系统时钟最高波特率达 230.4Kbps,如果使用外部设备提供的时钟,可以达到更高的速率。每一个 UART 单元包含一个 16 字节的 FIFO,用于数据的接收和发送。 S3C2410X UART 支持可编程波特率,红外发送/接收,一个或两个停止位,5bit/6bit/ 7bit/8bit 数据宽度和奇偶校验。
LED 项目:
main.c:
/*********************************************************************************************
* File: main.c
* Author: embest
* Desc: c main entry
* History:
*********************************************************************************************/
/*------------------------------------------------------------------------------------------*/
/* include files */
/*------------------------------------------------------------------------------------------*/
#include "2410lib.h"
#include "sys_init.h"
#include "fonts.h"
#include "led16x16.h"
extern char*adc_test(void);
/*********************************************************************************************
* name: main
* func: c code entry
* para: none
* ret: none
* modify:
* comment:
*********************************************************************************************/
int main(void)
{
sys_init(); // Initial system
uart_printf("\n Please Look At The 16X16 LEDS\n");
led_init(); // Initial led diplay
for(;;)
{
char* voltage = adc_test();
// 显示电压
char_out(0,voltage);
char_out(0,"V");
// 显示学号姓名
char_out(0," 20101330 DELM 19101307 lmz{hi ");
}
}
adc_test.c:
/*********************************************************************************************
* File: adc_test.c
* Author: embest
* Desc: ADC_Test
* History:
*********************************************************************************************/
/*------------------------------------------------------------------------------------------*/
/* include files */
/*------------------------------------------------------------------------------------------*/
#include "2410lib.h"
#include "stdio.h"
/*------------------------------------------------------------------------------------------*/
/* constants define */
/*------------------------------------------------------------------------------------------*/
#define REQCNT 100
#define ADC_FREQ 2500000
#define LOOP 10000
/*------------------------------------------------------------------------------------------*/
/* variables declare */
/*------------------------------------------------------------------------------------------*/
volatile UINT8T unPreScaler;
volatile char nEndTest;
/*********************************************************************************************
* name: adc_test
* func: ADC convert test
* para: none
* ret: none
* modify:
* comment:
*********************************************************************************************/
#include "2410lib.h"
#include "stdio.h"
#include "stdlib.h"
#define REQCNT 100
#define ADC_FREQ 2500000
#define LOOP 10000
char* adc_test(void)
{
int i;
UINT16T usConData;
float usEndData;
char* voltageString = (char*)malloc(8 * sizeof(char));
unPreScaler = PCLK / ADC_FREQ - 1;
rADCCON = (1 << 14) | (unPreScaler << 6) | (0 << 3) | (0 << 2) | (1 << 1);
usConData = rADCDAT0 & 0x3FF;
usEndData = usConData * 3.3000 / 0x3FF;
snprintf(voltageString, 8, "%0.4f", usEndData);
return voltageString;
}
fonts.c:
/*********************************************************************************************
* File: fonts.c
* Author: embest
* Desc: DotLed_Test
* History:
*********************************************************************************************/
/*------------------------------------------------------------------------------------------*/
/* include files */
/*------------------------------------------------------------------------------------------*/
#include "fonts.h"
// ------------------ ASCII字模的数据表 ------------------------ //
// nAsciiDot[] 替换了部分英文字符为汉字
unsigned char nAsciiDot[] = // ASCII
{
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // - -
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x18,0x3C,0x3C,0x3C,0x18,0x18, // -!-
0x18,0x00,0x18,0x18,0x00,0x00,0x00,0x00,
0x00,0x66,0x66,0x66,0x24,0x00,0x00,0x00, // -"-
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x6C,0x6C,0xFE,0x6C,0x6C, // -#-
0x6C,0xFE,0x6C,0x6C,0x00,0x00,0x00,0x00,
0x18,0x18,0x7C,0xC6,0xC2,0xC0,0x7C,0x06, // -$-
0x86,0xC6,0x7C,0x18,0x18,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0xC2,0xC6,0x0C,0x18, // -%-
0x30,0x60,0xC6,0x86,0x00,0x00,0x00,0x00,
0x00,0x00,0x38,0x6C,0x6C,0x38,0x76,0xDC, // -&-
0xCC,0xCC,0xCC,0x76,0x00,0x00,0x00,0x00,
0x00,0x30,0x30,0x30,0x60,0x00,0x00,0x00, // -'-
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x0C,0x18,0x30,0x30,0x30,0x30, // -(-
0x30,0x30,0x18,0x0C,0x00,0x00,0x00,0x00,
0x00,0x00,0x30,0x18,0x0C,0x0C,0x0C,0x0C, // -)-
0x0C,0x0C,0x18,0x30,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x66,0x3C,0xFF, // -*-
0x3C,0x66,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x7E, // -+-
0x18,0x18,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // -,-
0x00,0x18,0x18,0x18,0x30,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFE, // ---
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // -.-
0x00,0x00,0x18,0x18,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x02,0x06,0x0C,0x18, // -/-
0x30,0x60,0xC0,0x80,0x00,0x00,0x00,0x00,
0x00,0x00,0x7C,0xC6,0xC6,0xCE,0xD6,0xD6, // -0-
0xE6,0xC6,0xC6,0x7C,0x00,0x00,0x00,0x00,
0x00,0x00,0x18,0x38,0x78,0x18,0x18,0x18, // -1-
0x18,0x18,0x18,0x7E,0x00,0x00,0x00,0x00,
0x00,0x00,0x7C,0xC6,0x06,0x0C,0x18,0x30, // -2-
0x60,0xC0,0xC6,0xFE,0x00,0x00,0x00,0x00,
0x00,0x00,0x7C,0xC6,0x06,0x06,0x3C,0x06, // -3-
0x06,0x06,0xC6,0x7C,0x00,0x00,0x00,0x00,
0x00,0x00,0x0C,0x1C,0x3C,0x6C,0xCC,0xFE, // -4-
0x0C,0x0C,0x0C,0x1E,0x00,0x00,0x00,0x00,
0x00,0x00,0xFE,0xC0,0xC0,0xC0,0xFC,0x0E, // -5-
0x06,0x06,0xC6,0x7C,0x00,0x00,0x00,0x00,
0x00,0x00,0x38,0x60,0xC0,0xC0,0xFC,0xC6, // -6-
0xC6,0xC6,0xC6,0x7C,0x00,0x00,0x00,0x00,
0x00,0x00,0xFE,0xC6,0x06,0x06,0x0C,0x18, // -7-
0x30,0x30,0x30,0x30,0x00,0x00,0x00,0x00,
0x00,0x00,0x7C,0xC6,0xC6,0xC6,0x7C,0xC6, // -8-
0xC6,0xC6,0xC6,0x7C,0x00,0x00,0x00,0x00,
0x00,0x00,0x7C,0xC6,0xC6,0xC6,0x7E,0x06, // -9-
0x06,0x06,0x0C,0x78,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x00, // -:-
0x00,0x18,0x18,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x00, // -;-
0x00,0x18,0x18,0x30,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x06,0x0C,0x18,0x30,0x60, // -<-
0x30,0x18,0x0C,0x06,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0xFE,0x00, // -=-
0x00,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x60,0x30,0x18,0x0C,0x06, // ->-
0x0C,0x18,0x30,0x60,0x00,0x00,0x00,0x00,
0x00,0x00,0x7C,0xC6,0xC6,0x0C,0x18,0x18, // -?-
0x18,0x00,0x18,0x18,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x7C,0xC6,0xC6,0xDE,0xDE, // -@-
0xDE,0xDC,0xC0,0x7C,0x00,0x00,0x00,0x00,
0x00,0x00,0x10,0x38,0x6C,0xC6,0xC6,0xFE, // -A-
0xC6,0xC6,0xC6,0xC6,0x00,0x00,0x00,0x00,
0x00,0x00,0xFC,0x66,0x66,0x66,0x7C,0x66, // -B-
0x66,0x66,0x66,0xFC,0x00,0x00,0x00,0x00,
0x00,0x00,0x3C,0x66,0xC2,0xC0,0xC0,0xC0, // -C-
0xC0,0xC2,0x66,0x3C,0x00,0x00,0x00,0x00,
/*
0x00,0x00,0xF8,0x6C,0x66,0x66,0x66,0x66, // -D-
0x66,0x66,0x6C,0xF8,0x00,0x00,0x00,0x00,
*/
0x00, 0x7e, 0x02, 0x02, 0x42, 0x24, 0x14, 0x08, // -邓-
0x08, 0x14, 0x14, 0x22, 0x42, 0x80, 0x00, 0x00,
0x00, 0x7c, 0x44, 0x48, 0x48, 0x50, 0x48, 0x48,
0x44, 0x44, 0x44, 0x68, 0x50, 0x40, 0x40, 0x40,
/*
0x00,0x00,0xFE,0x66,0x62,0x68,0x78,0x68, // -E-
0x60,0x62,0x66,0xFE,0x00,0x00,0x00,0x00,
*/
0x00,0x00,0xFE,0x66,0x62,0x68,0x78,0x68, // -F-
0x60,0x60,0x60,0xF0,0x00,0x00,0x00,0x00,
0x00,0x00,0x3C,0x66,0xC2,0xC0,0xC0,0xDE, // -G-
0xC6,0xC6,0x66,0x3A,0x00,0x00,0x00,0x00,
0x00,0x00,0xC6,0xC6,0xC6,0xC6,0xFE,0xC6, // -H-
0xC6,0xC6,0xC6,0xC6,0x00,0x00,0x00,0x00,
0x00,0x00,0x3C,0x18,0x18,0x18,0x18,0x18, // -I-
0x18,0x18,0x18,0x3C,0x00,0x00,0x00,0x00,
0x00,0x00,0x1E,0x0C,0x0C,0x0C,0x0C,0x0C, // -J-
0xCC,0xCC,0xCC,0x78,0x00,0x00,0x00,0x00,
0x00,0x00,0xE6,0x66,0x6C,0x6C,0x78,0x78, // -K-
0x6C,0x66,0x66,0xE6,0x00,0x00,0x00,0x00,
/*
0x00,0x00,0xF0,0x60,0x60,0x60,0x60,0x60, // -L-
0x60,0x62,0x66,0xFE,0x00,0x00,0x00,0x00,
*/
0x7f, 0x04, 0x08, 0x1f, 0x28, 0x48, 0x8f, 0x00, // -磊-
0x7e, 0x10, 0x20, 0x7e, 0xa3, 0x22, 0x3e, 0x22,
0xfc, 0x00, 0x00, 0xf0, 0x10, 0x10, 0xf0, 0x00,
0xfe, 0x20, 0x40, 0xfc, 0x44, 0x44, 0x7c, 0x44,
/*
0x00,0x00,0xC6,0xEE,0xFE,0xFE,0xD6,0xC6, // -M-
0xC6,0xC6,0xC6,0xC6,0x00,0x00,0x00,0x00,
*/
0x00,0x00,0xC6,0xE6,0xF6,0xFE,0xDE,0xCE, // -N-
0xC6,0xC6,0xC6,0xC6,0x00,0x00,0x00,0x00,
0x00,0x00,0x38,0x6C,0xC6,0xC6,0xC6,0xC6, // -O-
0xC6,0xC6,0x6C,0x38,0x00,0x00,0x00,0x00,
0x00,0x00,0xFC,0x66,0x66,0x66,0x7C,0x60, // -P-
0x60,0x60,0x60,0xF0,0x00,0x00,0x00,0x00,
0x00,0x00,0x7C,0xC6,0xC6,0xC6,0xC6,0xC6, // -Q-
0xC6,0xD6,0xDE,0x7C,0x0C,0x0E,0x00,0x00,
0x00,0x00,0xFC,0x66,0x66,0x66,0x7C,0x6C, // -R-
0x66,0x66,0x66,0xE6,0x00,0x00,0x00,0x00,
0x00,0x00,0x7C,0xC6,0xC6,0x60,0x38,0x0C, // -S-
0x06,0xC6,0xC6,0x7C,0x00,0x00,0x00,0x00,
0x00,0x00,0x7E,0x7E,0x5A,0x18,0x18,0x18, // -T-
0x18,0x18,0x18,0x3C,0x00,0x00,0x00,0x00,
0x00,0x00,0xC6,0xC6,0xC6,0xC6,0xC6,0xC6, // -U-
0xC6,0xC6,0xC6,0x7C,0x00,0x00,0x00,0x00,
0x00,0x00,0xC6,0xC6,0xC6,0xC6,0xC6,0xC6, // -V-
0xC6,0x6C,0x38,0x10,0x00,0x00,0x00,0x00,
0x00,0x00,0xC6,0xC6,0xC6,0xC6,0xC6,0xD6, // -W-
0xD6,0xFE,0x6C,0x6C,0x00,0x00,0x00,0x00,
0x00,0x00,0xC6,0xC6,0x6C,0x6C,0x38,0x38, // -X-
0x6C,0x6C,0xC6,0xC6,0x00,0x00,0x00,0x00,
0x00,0x00,0x66,0x66,0x66,0x66,0x3C,0x18, // -Y-
0x18,0x18,0x18,0x3C,0x00,0x00,0x00,0x00,
0x00,0x00,0xFE,0xC6,0x86,0x0C,0x18,0x30, // -Z-
0x60,0xC2,0xC6,0xFE,0x00,0x00,0x00,0x00,
0x00,0x00,0x3C,0x30,0x30,0x30,0x30,0x30, // -[-
0x30,0x30,0x30,0x3C,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x80,0xC0,0xE0,0x70,0x38, // -\-
0x1C,0x0E,0x06,0x02,0x00,0x00,0x00,0x00,
0x00,0x00,0x3C,0x0C,0x0C,0x0C,0x0C,0x0C, // -]-
0x0C,0x0C,0x0C,0x3C,0x00,0x00,0x00,0x00,
0x10,0x38,0x6C,0xC6,0x00,0x00,0x00,0x00, // -^-
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // -_-
0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,
0x30,0x30,0x18,0x00,0x00,0x00,0x00,0x00, // -`-
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x78,0x0C,0x7C, // -a-
0xCC,0xCC,0xCC,0x76,0x00,0x00,0x00,0x00,
0x00,0x00,0xE0,0x60,0x60,0x78,0x6C,0x66, // -b-
0x66,0x66,0x66,0xDC,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x7C,0xC6,0xC0, // -c-
0xC0,0xC0,0xC6,0x7C,0x00,0x00,0x00,0x00,
0x00,0x00,0x1C,0x0C,0x0C,0x3C,0x6C,0xCC, // -d-
0xCC,0xCC,0xCC,0x76,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x7C,0xC6,0xFE, // -e-
0xC0,0xC0,0xC6,0x7C,0x00,0x00,0x00,0x00,
0x00,0x00,0x38,0x6C,0x64,0x60,0xF0,0x60, // -f-
0x60,0x60,0x60,0xF0,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x76,0xCC,0xCC, // -g-
0xCC,0xCC,0xCC,0x7C,0x0C,0xCC,0x78,0x00,
/*
0x00,0x00,0xE0,0x60,0x60,0x6C,0x76,0x66, // -h-
0x66,0x66,0x66,0xE6,0x00,0x00,0x00,0x00,
*/
0x10, 0x10, 0x10, 0x13, 0xfc, 0x10, 0x31, 0x39, // -杭-
0x55, 0x55, 0x91, 0x11, 0x11, 0x12, 0x12, 0x14,
0x80, 0x40, 0x40, 0xfc, 0x00, 0x00, 0xf0, 0x10,
0x10, 0x10, 0x10, 0x12, 0x12, 0x12, 0x0e, 0x00,
/*
0x00,0x00,0x18,0x18,0x00,0x38,0x18,0x18, // -i-
0x18,0x18,0x18,0x3C,0x00,0x00,0x00,0x00,
*/
0x00,0x00,0x06,0x06,0x00,0x0E,0x06,0x06, // -j-
0x06,0x06,0x06,0x06,0x66,0x66,0x3C,0x00,
0x00,0x00,0xE0,0x60,0x60,0x66,0x6C,0x78, // -k-
0x78,0x6C,0x66,0xE6,0x00,0x00,0x00,0x00,
/*
0x00,0x00,0x38,0x18,0x18,0x18,0x18,0x18, // -l-
0x18,0x18,0x18,0x3C,0x00,0x00,0x00,0x00,
*/
0x01, 0x01, 0x7f, 0x03, 0x05, 0x09, 0x31, 0xc1, // -李-
0x0f, 0x00, 0x00, 0xff, 0x01, 0x01, 0x05, 0x02,
0x00, 0x00, 0xfc, 0x80, 0x40, 0x20, 0x18, 0x06,
0xe0, 0x40, 0x80, 0xfe, 0x00, 0x00, 0x00, 0x00,
/*
0x00,0x00,0x00,0x00,0x00,0xEC,0xFE,0xD6, // -m-
0xD6,0xD6,0xD6,0xD6,0x00,0x00,0x00,0x00,
*/
0x00,0x00,0x00,0x00,0x00,0xDC,0x66,0x66, // -n-
0x66,0x66,0x66,0x66,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x7C,0xC6,0xC6, // -o-
0xC6,0xC6,0xC6,0x7C,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0xDC,0x66,0x66, // -p-
0x66,0x66,0x66,0x7C,0x60,0x60,0xF0,0x00,
0x00,0x00,0x00,0x00,0x00,0x76,0xCC,0xCC, // -q-
0xCC,0xCC,0xCC,0x7C,0x0C,0x0C,0x1E,0x00,
0x00,0x00,0x00,0x00,0x00,0xDC,0x76,0x62, // -r-
0x60,0x60,0x60,0xF0,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x7C,0xC6,0x60, // -s-
0x38,0x0C,0xC6,0x7C,0x00,0x00,0x00,0x00,
0x00,0x00,0x10,0x30,0x30,0xFC,0x30,0x30, // -t-
0x30,0x30,0x36,0x1C,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0xCC,0xCC,0xCC, // -u-
0xCC,0xCC,0xCC,0x76,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x66,0x66,0x66, // -v-
0x66,0x66,0x3C,0x18,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0xC6,0xC6,0xC6, // -w-
0xD6,0xD6,0xFE,0x6C,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0xC6,0x6C,0x38, // -x-
0x38,0x38,0x6C,0xC6,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0xC6,0xC6,0xC6, // -y-
0xC6,0xC6,0xC6,0x7E,0x06,0x0C,0xF8,0x00,
/*
0x00,0x00,0x00,0x00,0x00,0xFE,0xCC,0x18, // -z-
0x30,0x60,0xC6,0xFE,0x00,0x00,0x00,0x00,
*/
0x01, 0x01, 0x01, 0x01, 0x1f, 0x10, 0x1f, 0x10, // -卓-
0x1f, 0x11, 0x01, 0xff, 0x01, 0x01, 0x01, 0x01,
0x00, 0xfc, 0x00, 0x00, 0xf0, 0x10, 0xf0, 0x10,
0xf0, 0x10, 0x00, 0xfe, 0x00, 0x00, 0x00, 0x00,
/*
0x00,0x00,0x0E,0x18,0x18,0x18,0x70,0x18, // -{-
0x18,0x18,0x18,0x0E,0x00,0x00,0x00,0x00,
*/
0x00,0x00,0x18,0x18,0x18,0x18,0x00,0x18, // -|-
0x18,0x18,0x18,0x18,0x00,0x00,0x00,0x00,
0x00,0x00,0x70,0x18,0x18,0x18,0x0E,0x18, // -}-
0x18,0x18,0x18,0x70,0x00,0x00,0x00,0x00,
0x00,0x00,0x76,0xDC,0x00,0x00,0x00,0x00, // -~-
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};
struct fonts_struct fonts[FONT_COUNT] = {
{8,16,nAsciiDot,' ','~'},
};
LCD 项目:
main.c:
/*********************************************************************************************
* File: main.c
* Author: embest
* Desc: c main entry
* History:
*********************************************************************************************/
/*------------------------------------------------------------------------------------------*/
/* include files */
/*------------------------------------------------------------------------------------------*/
#include "2410lib.h"
#include "sys_init.h"
#include "fonts.h"
#include "led16x16.h"
extern void adc_test(void);
extern void color_lcd_test(void);
extern void lcd_init_app(void);
/*********************************************************************************************
* name: main
* func: c code entry
* para: none
* ret: none
* modify:
* comment:
*********************************************************************************************/
int main(void)
{
sys_init(); // Initial system
uart_printf("\n Please Look At The 16X16 LEDS\n");
led_init(); // Initial led diplay
lcd_init_app();
for(;;)
{
adc_test();
}
}
adc_test.c:
/*********************************************************************************************
* File: adc_test.c
* Author: embest
* Desc: ADC_Test
* History:
*********************************************************************************************/
/*------------------------------------------------------------------------------------------*/
/* include files */
/*------------------------------------------------------------------------------------------*/
#include "2410lib.h"
#include "sys_init.h"
#include "fonts.h"
#include "led16x16.h"
#include
/*------------------------------------------------------------------------------------------*/
/* constants define */
/*------------------------------------------------------------------------------------------*/
#define REQCNT 100
#define ADC_FREQ 2500000
#define LOOP 10000
/*------------------------------------------------------------------------------------------*/
/* variables declare */
/*------------------------------------------------------------------------------------------*/
volatile UINT8T unPreScaler1;
volatile char nEndTest;
extern void char_out(u8 font, u8 *str);
extern void color_lcd_test(void);
/*********************************************************************************************
* name: adc_test
* func: ADC convert test
* para: none
* ret: none
* modify:
* comment:
*********************************************************************************************/
void adc_test(void)
{
u8 str[7];
int i,j;
UINT16T usConData;
float usEndData;
char str1[20];
uart_printf("\n ADC_IN Test\n");
uart_printf(" ADC conv. freq. = %dHz\n",ADC_FREQ);
unPreScaler1 = PCLK/ADC_FREQ - 1;
// Enable prescaler,ain0,normal,start by read
rADCCON=(1<<14)|(unPreScaler1<<6)|(0<<3)|(0<<2)|(1<<1);
uart_printf(" Please adjust AIN0 value!\n");
uart_printf(" The results of ADC are:\n");
usConData=rADCDAT0&0x3FF;
// Sample and show data by UART
for(j = 0; j < 20; j++)
{
while(!(rADCCON & 0x8000));
usConData = rADCDAT0&0x3FF;
usEndData = usConData * 3.3000 / 0x3FF;
uart_printf(" %0.4f ",usEndData);
sprintf(str1, "%.4f", usEndData);
//char_out(0, (u8 *)str1);
//char_out(0,"v ");
color_lcd_test();
usEndData = usEndData - (int)usEndData;
for(i = 0; i < 4; i++)
{
usEndData = usEndData*10;
usEndData = usEndData-(int)usEndData;
}
delay(10000);
}
uart_printf(" End.\n");
}
color_lcd_test.c:
/*********************************************************************************************
* File: lcdapp.c
* Author: Embest
* Desc: LCD_Test
* History:
*********************************************************************************************/
/*------------------------------------------------------------------------------------------*/
/* include files */
/*------------------------------------------------------------------------------------------*/
#include
#include "2410lib.h"
#include "lcdlib.h"
#include "glib.h"
#include "lcd.h"
#include
#include
#include "sys_init.h"
#include "fonts.h"
#include "led16x16.h"
/*------------------------------------------------------------------------------------------*/
/* constant define */
/*------------------------------------------------------------------------------------------*/
#define LCD_BUF_SIZE (SCR_XSIZE_TFT_640480*SCR_YSIZE_TFT_640480/2)
#define LCD_ACTIVE_BUFFER (0x33800000)
#define LCD_VIRTUAL_BUFFER (0x33800000 + LCD_BUF_SIZE)
#define LCD_D_OFF rGPCDAT &= ~(1 << 4);
#define LCD_D_ON rGPCDAT |= (1 << 4);
#define REQCNT 100
#define ADC_FREQ 2500000
#define LOOP 10000
/*------------------------------------------------------------------------------------------*/
/* extern variables */
/*------------------------------------------------------------------------------------------*/
#ifdef BOARDTEST_EXH
#undef BOARDTEST
#endif
#ifndef BOARDTEST
volatile UINT8T unPreScaler;
//volatile char nEndTest;
extern void char_out(u8 font, u8 *str);
extern void color_lcd_test(void);
extern const UINT8T g_ucBitmap[][76800];
extern UINT8T g_ucAscii8x16[];
extern UINT8T g_auc_Ascii6x8[];
extern UINT8T g_auc_hzk24[];
#endif
/*------------------------------------------------------------------------------------------*/
/* function declare */
/*------------------------------------------------------------------------------------------*/
void Lcd_DspAscII6x8(UINT16T x0, UINT16T y0, UINT16T ForeColor, UINT8T * s);
void Lcd_DspAscII8x16(UINT16T x0, UINT16T y0, UINT16T ForeColor, UINT8T * s);
//void Lcd_DspHz12(UINT16T x0, UINT16T y0, UINT16T ForeColor, UINT8T *s);
//void Lcd_DspHz16(UINT16T x0, UINT16T y0, UINT16T ForeColor, UINT8T *s);
void Lcd_DspHz24(UINT16T x0, UINT16T y0, UINT16T ForeColor, UINT8T *s);
//void Lcd_DspHz24s(UINT16T x0, UINT16T y0, UINT16T ForeColor, UINT8T *s);
void Lcd_Draw_HLine(INT16T usX0, INT16T usX1, INT16T usY0, UINT16T ucColor, UINT16T usWidth);
void Lcd_Draw_VLine (INT16T usY0, INT16T usY1, INT16T usX0, UINT16T ucColor, UINT16T usWidth);
void lcd_clr(void);
extern void Lcd_port_init(void);
extern void Lcd_Port_Return(void);
/*********************************************************************************************
* name: lcd_init_app
* func: lcd application initialization code
* para: none
* ret: none
* modify:
* comment:
*********************************************************************************************/
void lcd_init_app()
{
Lcd_port_init();
Lcd_Init(MODE_TFT_16BIT_800480);
Glib_Init(MODE_TFT_16BIT_800480);
Glib_ClearScr(0, MODE_TFT_16BIT_800480);
Lcd_PowerEnable(0, 1);
Lcd_EnvidOnOff(1);
uart_printf(" [TFT 64K COLOR(16bit/1pixel) LCD TEST]\n");
}
/*********************************************************************************************
* name: lcd_init_app_end
* func: end lcd application initialization
* para: none
* ret: none
* modify:
* comment:
*********************************************************************************************/
void lcd_init_app_end()
{
Lcd_EnvidOnOff(0);
Lcd_Port_Return();
}
#ifndef BOARDTEST
/*********************************************************************************************
* name: Lcd_DspHz24
* func: display 24x24 Chinese Symbol on Lcd
* para: UINT16T x0 -- x coordinate of start point
* UINT16T y0 -- y coordinate of start point
* UINT16T ForeColor -- foreground color of lcd
* UINT8T *s -- string to display
* ret: none
* modify:
* comment:
*********************************************************************************************/
void Lcd_DspHz24(UINT16T x0, UINT16T y0, UINT16T ForeColor, UINT8T *s)
{
INT16T i,j,k,x,y,xx;
UINT8T qm,wm;
INT32T ulOffset;
INT8T hzbuf[72];
for(i = 0; i < strlen((const char*)s); i++)
{
if(((UINT8T)(*(s+i))) < 161)
{
break;
}
else
{
qm = *(s+i) - 176; //161;
wm = *(s+i + 1) - 161;
ulOffset = (INT32T)(qm * 94 + wm) * 72;
for (j = 0; j < 72; j ++)
{
hzbuf[j] = g_auc_hzk24[ulOffset + j];
}
for(y = 0; y < 24; y++)
{
for(x = 0; x < 24; x++)
{
k = x % 8;
if (hzbuf[y * 3 + x / 8] & (0x80 >> k))
{
xx = x0 + x + i*12;
PutPixel( xx, y + y0, (UINT16T)ForeColor);
}
}
}
i++;
}
}
}
#endif
/*********************************************************************************************
* name: Lcd_DspAscII6x8()
* func: display 6x8 ASCII character string
* para: usX0,usY0 -- ASCII character string's start point coordinate
* ForeColor -- appointed color value
* pucChar -- ASCII character string
* ret: none
* modify:
* comment:
*********************************************************************************************/
#define XWIDTH 6
extern UINT8T g_ucAscii6x8[];
void Lcd_DspAscII6x8(UINT16T usX0, UINT16T usY0,UINT16T ForeColor, UINT8T* pucChar)
{
UINT32T i,j;
UINT8T ucTemp;
while( *pucChar != 0 )
{
for( i=0; i < 8; i++ )
{
ucTemp = g_ucAscii6x8[(*pucChar) * 8 + i];
for( j = 0; j < 8; j++ )
{
if( (ucTemp & (0x80 >> j)) != 0 )
{
PutPixel(usX0 + i, usY0 + 8 - j, (UINT16T)ForeColor);
}
}
}
usX0 += XWIDTH;
pucChar++;
}
}
#ifndef BOARDTEST
/*********************************************************************************************
* name: Lcd_DspAscII8X16
* func: display 8x16 AscII Symbol on Lcd
* para: UINT16T x0 -- x coordinate of start point
* UINT16T y0 -- y coordinate of start point
* UINT16T ForeColor -- foreground color of lcd
* UINT8T *s -- string to display
* ret: none
* modify:
* comment:
*********************************************************************************************/
void Lcd_DspAscII8x16(UINT16T x0, UINT16T y0, UINT16T ForeColor, UINT8T * s)
{
INT16T i,j,k,x,y,xx;
UINT8T qm;
INT32T ulOffset;
INT8T ywbuf[16];
for(i = 0; i < strlen((const char*)s); i++)
{
if((UINT8T)*(s+i) >= 161)
{
return;
}
else
{
qm = *(s+i);
ulOffset = (INT32T)(qm) * 16;
for (j = 0; j < 16; j ++)
{
ywbuf[j] = g_ucAscii8x16[ulOffset + j];
}
for(y = 0; y < 16; y++)
{
for(x = 0; x < 8; x++)
{
k = x % 8;
if (ywbuf[y] & (0x80 >> k))
{
xx = x0 + x + i*8;
PutPixel( xx, y + y0, (UINT16T)ForeColor);
}
}
}
}
}
}
#endif
/*********************************************************************************************
* name: lcd_clr
* func: clear LCD screen
* para: none
* ret: none
* modify:
* comment:
*********************************************************************************************/
void lcd_clr(void)
{
UINT32T i;
UINT32T *pDisp = (UINT32T*)LCD_ACTIVE_BUFFER;
for (i = 0; i < (SCR_XSIZE_CSTN * SCR_YSIZE_CSTN /4); i++)
{
*pDisp = 0xffffffff;//ALLWHITE;
}
}
/*********************************************************************************************
* name: lcd_clr_rect
* func: fill appointed area with appointed color
* para: usLeft,usTop,usRight,usBottom -- area's rectangle acme coordinate
* ucColor -- appointed color value
* ret: none
* modify:
* comment: also as clear screen function
*********************************************************************************************/
void lcd_clr_rect(INT16T usLeft, INT16T usTop, INT16T usRight, INT16T usBottom, UINT16T ucColor)
{
UINT32T i, j;
// UINT8T *pDisp = (UINT8T*)LCD_ACTIVE_BUFFER;
for (i = usLeft; i < usRight; i++)
for (j = usTop; j < usBottom; j++)
{
PutPixel(i,j,ucColor);
//*(pDisp+i+j) = ucColor;
}
}
/*********************************************************************************************
* name: Lcd_Draw_Box()
* func: Draw rectangle with appointed color
* para: usLeft,usTop,usRight,usBottom -- rectangle's acme coordinate
* ucColor -- appointed color value
* ret: none
* modify:
* comment:
*********************************************************************************************/
void Lcd_Draw_Box(INT16T usLeft, INT16T usTop, INT16T usRight, INT16T usBottom, UINT16T ucColor)
{
Lcd_Draw_HLine(usLeft, usRight, usTop, ucColor, 1);
Lcd_Draw_HLine(usLeft, usRight, usBottom, ucColor, 1);
Lcd_Draw_VLine(usTop, usBottom, usLeft, ucColor, 1);
Lcd_Draw_VLine(usTop, usBottom, usRight, ucColor, 1);
}
/*********************************************************************************************
* name: Lcd_Draw_Line()
* func: Draw line with appointed color
* para: usX0,usY0 -- line's start point coordinate
* usX1,usY1 -- line's end point coordinate
* ucColor -- appointed color value
* usWidth -- line's width
* ret: none
* modify:
* comment:
*********************************************************************************************/
/*********************************************************************************************
* name: Lcd_Draw_HLine()
* func: Draw horizontal line with appointed color
* para: usX0,usY0 -- line's start point coordinate
* usX1 -- line's end point X-coordinate
* ucColor -- appointed color value
* usWidth -- line's width
* ret: none
* modify:
* comment:
*********************************************************************************************/
void Lcd_Draw_HLine(INT16T usX0, INT16T usX1, INT16T usY0, UINT16T ucColor, UINT16T usWidth)
{
INT16T usLen;
if( usX1 < usX0 )
{
GUISWAP (usX1, usX0);
}
while( (usWidth--) > 0 )
{
usLen = usX1 - usX0 + 1;
while( (usLen--) > 0 )
{
PutPixel(usX0 + usLen, usY0, ucColor);
}
usY0++;
}
}
/*********************************************************************************************
* name: Lcd_Draw_VLine()
* func: Draw vertical line with appointed color
* para: usX0,usY0 -- line's start point coordinate
* usY1 -- line's end point Y-coordinate
* ucColor -- appointed color value
* usWidth -- line's width
* ret: none
* modify:
* comment:
*********************************************************************************************/
void Lcd_Draw_VLine (INT16T usY0, INT16T usY1, INT16T usX0, UINT16T ucColor, UINT16T usWidth)
{
INT16T usLen;
if( usY1 < usY0 )
{
GUISWAP (usY1, usY0);
}
while( (usWidth--) > 0 )
{
usLen = usY1 - usY0 + 1;
while( (usLen--) > 0 )
{
PutPixel(usX0, usY0 + usLen, ucColor);
}
usX0++;
}
}
/*********************************************************************************************
* name: color_lcd_test()
* func: LCD test function
* para: none
* ret: none
* modify:
* comment:
*********************************************************************************************/
int MapValue(float value, float inMin, float inMax, int outMin, int outMax)
{
// Perform the linear mapping
return (outMax - ((value - inMin) * (outMax - outMin) / (inMax - inMin) + outMin));
}
int ConvertValue(float value)
{
// Define the input range
float inMin = 0.0;
float inMax = 3.5;
// Define the output range
int outMin = 100;
int outMax = 400;
// Map the value from the input range to the output range
return MapValue(value, inMin, inMax, outMin, outMax);
}
u8* float_to_string1(float number, u8* result, int precision) {
sprintf((char*)result, "%.*f", precision, number);
return result;
}
void color_lcd_test(void)
{
u8 str[7];
char item[7];
int i,j;
UINT16T usConData;
float usEndData;
int temp = 200;
Glib_FilledRectangle(5,5,795,475,WHITE);
Glib_Line(60,10,60,400,BLACK);
Glib_Line(60,400,750,400,BLACK);
Lcd_DspHz24(75,420,BLACK,"邓磊");
Lcd_DspAscII8x16(75,450,BLACK,"20101330");
Lcd_DspHz24(250,420,BLACK,"李卓杭");
Lcd_DspAscII8x16(250,450,BLACK,"19101307");
Lcd_DspHz24(10,35,BLACK,"电压");
Lcd_DspAscII8x16(55,35,BLACK,"(V)");
Lcd_DspAscII8x16(30,20,BLACK,"3.3V");
Lcd_DspAscII8x16(30,290,BLACK,"0.0V");
Lcd_DspHz24(720,420,BLACK,"时间");
Lcd_DspAscII8x16(765,420,BLACK,"(S)");
unPreScaler = PCLK/ADC_FREQ - 1;
// Enable prescaler,ain0,normal,start by read
rADCCON=(1<<14)|(unPreScaler<<6)|(0<<3)|(0<<2)|(1<<1);
uart_printf(" Please adjust AIN0 value!\n");
uart_printf(" The results of ADC are:\n");
usConData=rADCDAT0&0x3FF;
for(j = 0; j < 2000000; j++)
{
int preBoundary = 60+ ((j*5) % 690);
int sufBoundary =65+ ((j*5) % 690);
while(!(rADCCON & 0x8000));
usConData = rADCDAT0&0x3FF;
usEndData = usConData * 3.3000 / 0x3FF;
//uart_printf(" %0.4f ",usEndData);
float_to_string1(usEndData,str,4);
Lcd_DspAscII8x16(30,750,BLACK,str);
sprintf(item, "vol is %s V.", str);
Lcd_DspAscII8x16(600,23,BLACK,item);
delay(1000);
Lcd_DspAscII8x16(600,23,WHITE,item);
Glib_Line(preBoundary,temp,sufBoundary,ConvertValue(usEndData),BLACK);
temp = ConvertValue(usEndData);
if(preBoundary == 740){
Glib_FilledRectangle(62,5,750,390,WHITE);
}
usEndData = usEndData - (int)usEndData;
for(i = 0; i < 4; i++)
{
usEndData = usEndData*10;
usEndData = usEndData-(int)usEndData;
}
delay(1000);
}
}
本次实验主要涉及了嵌入式系统开发的多方面知识,如芯片结构、I/O 接口编程、LCD 屏幕控制、ADC 转换、串口通信等。通过实验,我对 S3C2410 芯片的结构和特点有了更深入的理解,学会了使用 GPIO 口编程控制 LED 点阵屏的显示,掌握了 LCD 屏幕控制的编程方法,并能够实现在 LCD 屏上同步显示采样数据。同时,我还学习了 ADC 转换的原理和使用方法,实现了采集电压模拟量并在 LED 点阵屏上动态显示电压值和实验者的学号和姓名。在实验中,我也遇到了一些问题,如学号和姓名在 LED 屏幕上的滚动显示和 LCD 屏幕上的数据显示的同步问题,但通过不断地调试和修改代码,最终成功解决了这些问题。通过本次实验,我不仅掌握了嵌入式系统开发的基本知识和技能,还加深了对嵌入式系统的理解和应用。