本帖最后由 sujingliang 于 2024-11-25 15:38 编辑
能够入围本次AT-START-L021开发板的测评,深感荣幸与激动。感谢21IC和雅特力科技的信任与期待。
一、谈一下对AT-START-L021开发板的理解
1、板载AT-LINK可以通过CMSIS-DAP Debugger方式方便地下载和调整程序。AT-LINK主控是AT32F403ACCT7,比本次的评测对象AT32L021C8T7性能还要强悍。
2、AT-LINK提供了5v和3.3v电平转换IC,可以满足5v和3.3vMCU的烧录。
3、LDO支持3.3v和1.8v供电,满足AT32L021C8T7通用和低电压驱动的需要。
4、3个user LED通过三极管驱动,用料非要这么足吗?这应该是为1.8v供电准备的,对于3.3v供电应该可以不用。
5、提供arduino uno连接接口。
二、驱动8位并口屏
1、硬件连接
利用arduino uno接口中如下几个引脚:
#define LCD_CS GPIOB,GPIO_PINS_10 //PB10
#define LCD_RS GPIOA,GPIO_PINS_8 //PA8
#define LCD_WR GPIOB,GPIO_PINS_4 //PB4
#define LCD_RD GPIOB,GPIO_PINS_3 //PB3
#define LCD_RST GPIOB,GPIO_PINS_5 //PB5
#define LCD_LED GPIOA,GPIO_PINS_10 //PA10
//#define USE_HIGHEIGHT 1 //使用高八位
#define LCD_DB0 GPIOA,GPIO_PINS_9 //PA9
#define LCD_DB1 GPIOB,GPIO_PINS_7 //PB7
#define LCD_DB2 GPIOA,GPIO_PINS_15 //PA15
#define LCD_DB3 GPIOA,GPIO_PINS_7 //PA7
#define LCD_DB4 GPIOA,GPIO_PINS_6 //PA6
#define LCD_DB5 GPIOA,GPIO_PINS_5 //PA5
#define LCD_DB6 GPIOB,GPIO_PINS_9 //PB9
#define LCD_DB7 GPIOB,GPIO_PINS_8 //PB8
2、gpio操作定义
对每一个利用到的引脚做如下GPIO设置、重置定义
#define LCD_DB0_SET gpio_bits_set(LCD_DB0)
#define LCD_DB0_CLR gpio_bits_reset(LCD_DB0)
3、并口输入数据函数
typedef struct {
gpio_type *GPIOx;
uint16_t GPIO_Pin; // GPIO引脚
} GPIO_PinConfig;
// 初始化GPIO配置数组
GPIO_PinConfig dbPins[NUM_BITS] = {
{LCD_DB0},
{LCD_DB1},
{LCD_DB2},
{LCD_DB3},
{LCD_DB4},
{LCD_DB5},
{LCD_DB6},
{LCD_DB7}
};
void gpio_lcd_write_data_word(uint8_t* data, size_t length) {
for (int i = 0; i < length; i++) {
for (int bit = 0; bit < NUM_BITS; bit++) {
// 检查当前位是否为1
if (data[i] & (1 << bit)) {
gpio_bits_set(dbPins[bit].GPIOx, dbPins[bit].GPIO_Pin);
} else {
gpio_bits_reset(dbPins[bit].GPIOx, dbPins[bit].GPIO_Pin);
}
}
LCD_WR_CLR;
LCD_WR_SET;
// 如果需要,可以在这里添加延时或其他处理
}
}
4、写命令函数
void lcd_write_comm_word(uint16_t cmd)
{
unsigned char c[2];
// c[0] = (cmd >> 8) & 0xFF;
// c[1] = cmd & 0xFF;
c[0]=0x00;
c[1]=cmd;
LCD_CS_CLR;
LCD_RS_CLR;
gpio_lcd_write_data_word(c, 2);
LCD_CS_SET;
}
5、写数据函数
void lcd_write_data_word(uint16_t data)
{
unsigned char c[2];
c[0] = (data >> 8) & 0xFF;
c[1] = data & 0xFF;
LCD_CS_CLR;
LCD_RS_SET;
gpio_lcd_write_data_word(c, 2);
LCD_CS_SET;
}
6、写寄存器函数
void lcd_write_register_word(uint16_t addr, uint16_t data)
{
lcd_write_comm_word(addr);
lcd_write_data_word(data);
}
7、LCD gpio初始化函数
static void lcd_gpio_init(void)
{
gpio_init_type gpio_init_struct;
/* enable the led clock */
crm_periph_clock_enable(CRM_GPIOA_PERIPH_CLOCK, TRUE);
crm_periph_clock_enable(CRM_GPIOB_PERIPH_CLOCK, TRUE);
/* set default parameter */
gpio_default_para_init(&gpio_init_struct);
/* configure the lcd GPIOA gpio */
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
gpio_init_struct.gpio_mode = GPIO_MODE_OUTPUT;
gpio_init_struct.gpio_pins = GPIO_PINS_8|GPIO_PINS_10|GPIO_PINS_9|GPIO_PINS_15|GPIO_PINS_7|GPIO_PINS_6|GPIO_PINS_5;
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
gpio_init(GPIOA, &gpio_init_struct);
/* configure the lcd GPIOB gpio */
gpio_init_struct.gpio_pins = GPIO_PINS_10|GPIO_PINS_4|GPIO_PINS_3|GPIO_PINS_5|GPIO_PINS_7|GPIO_PINS_9|GPIO_PINS_8;
gpio_init(GPIOB, &gpio_init_struct);
}
8、LCD初始化函数
void InitLCD()
{
//printf("reset\r\n");
lcd_gpio_init();
LCD_Reset();
LCD_RD_SET;
Delay_Ms(150);
//printf("ili9225 Initial\r\n");
Delay_Ms(50);
LCD_CS_CLR;
lcd_write_register_word(0x10, 0x0000);
lcd_write_register_word(0x11, 0x0000);
lcd_write_register_word(0x12, 0x0000);
lcd_write_register_word(0x13, 0x0000);
lcd_write_register_word(0x14, 0x0000);
Delay_Ms(40);
lcd_write_register_word(0x11, 0x0018);
lcd_write_register_word(0x12, 0x6121);
lcd_write_register_word(0x13, 0x006F);
lcd_write_register_word(0x14, 0x495F);
lcd_write_register_word(0x10, 0x0800);
Delay_Ms(10);
lcd_write_register_word(0x11, 0x103B);
Delay_Ms(50);
lcd_write_register_word(0x01, 0x031C); //0x021C 控制反转
lcd_write_register_word(0x02, 0x0100);
lcd_write_register_word(0x03, 0x1038);
lcd_write_register_word(0x07, 0x0000);
lcd_write_register_word(0x08, 0x0808);
lcd_write_register_word(0x0b, 0x1100);
lcd_write_register_word(0x0c, 0x0000);
lcd_write_register_word(0x0f, 0x0D01);
lcd_write_register_word(0x15, 0x0020);
lcd_write_register_word(0x20, 0x0000);
lcd_write_register_word(0x21, 0x0000);
lcd_write_register_word(0x30, 0x0000);
lcd_write_register_word(0x31, 0x00DB);
lcd_write_register_word(0x32, 0x0000);
lcd_write_register_word(0x33, 0x0000);
lcd_write_register_word(0x34, 0x00DB);
lcd_write_register_word(0x35, 0x0000);
lcd_write_register_word(0x36, 0x00AF);
lcd_write_register_word(0x37, 0x0000);
lcd_write_register_word(0x38, 0x00DB);
lcd_write_register_word(0x39, 0x0000);
lcd_write_register_word(0x50, 0x0000);
lcd_write_register_word(0x51, 0x0808);
lcd_write_register_word(0x52, 0x080A);
lcd_write_register_word(0x53, 0x000A);
lcd_write_register_word(0x54, 0x0A08);
lcd_write_register_word(0x55, 0x0808);
lcd_write_register_word(0x56, 0x0000);
lcd_write_register_word(0x57, 0x0A00);
lcd_write_register_word(0x58, 0x0710);
lcd_write_register_word(0x59, 0x0710);
lcd_write_register_word(0x07, 0x0012);
Delay_Ms(50);
lcd_write_register_word(0x07, 0x1017);
lcd_write_comm_word(0x22);
LCD_CS_SET;
LCD_LED_SET;
}
9、设置窗口函数
void setXY(unsigned char x1, unsigned char y1, unsigned char x2, unsigned char y2)
{
#if 1
lcd_write_register_word(0x36,y2);
lcd_write_register_word(0x37,y1);
lcd_write_register_word(0x38,x2);
lcd_write_register_word(0x39,x1);
lcd_write_register_word(0x20,y1);
lcd_write_register_word(0x21,x1);
#endif
}
10、画点函数
void setPixel(uint16_t color)
{
lcd_write_data_word(color);
}
11、ASCII和汉字显示函数
void GUI_Write16CnChar(unsigned char x, unsigned char y, unsigned char *cn, unsigned short wordColor, unsigned short backColor)
{
uint8_t i, j, wordNum,mx,my,wordByte;
uint8_t color;
mx=x;
my=y;
while (*cn != '\0')
{
if(*cn<128){
wordNum = *cn - 32;
setXY(mx,my,mx+7, my+15);
for (wordByte=0; wordByte<16; wordByte++)
{
color = Font_Data[wordNum].dat[wordByte];
for (j=0; j<8; j++)
{
if ((color&0x80) == 0x80)
{
setPixel(wordColor);
}
else
{
setPixel(backColor);
}
color <<= 1;
}
}
cn++;
mx +=8;
}
else
{
setXY(mx, my, mx+15, my+15);
for (wordNum=0; wordNum<(sizeof(CnChar16x16) / sizeof(CnChar16x16[0])); wordNum++)
{ //wordNum扫描字库的字数
if ((CnChar16x16[wordNum].Index[0]==*cn)
&&(CnChar16x16[wordNum].Index[1]==*(cn+1)))
{
for(i=0; i<32; i++)
{ //MSK的位数
color=CnChar16x16[wordNum].Msk[i];
for(j=0;j<8;j++)
{
if((color&0x80)==0x80)
{
lcd_write_data_word(wordColor);
}
else
{
lcd_write_data_word(backColor);
}
color<<=1;
}//for(j=0;j<8;j++)结束
}
}
} //for (wordNum=0; wordNum<20; wordNum++)结束
cn += 2;
mx += 16;
}
}
}
12、画图片函数
void GUI_Showbmp(unsigned char x, unsigned char y, unsigned char wide, unsigned char high,unsigned short wordColor,unsigned short backColor)
{
uint16_t j,color = 0, tmp = 0, num = 0;
setXY(x, y, x+wide-1, y+high-1);
num = wide * high/8;
do
{
color = bmp[tmp];
for (j=0; j<8; j++)
{
if ((color&0x80) == 0x80)
{
setPixel(wordColor);
}
else
{
setPixel(backColor);
}
color <<= 1;
}
tmp += 1;
}while(tmp < num);
}
三、运行效果
test1.rar
(73.6 KB)
|
|