LCD DMA day59

十四:LCD 显示屏

一:基础概念

访问:

​ 1.传输bank地址和行地址

​ 2传输列地址及读写信号

​ 3.写:写数据到DATA(先写到数据总线中,再数据操作)

​ 读: (先数据操作,再从数据总线拿出数据)从DATA获取数据

二:代码

#include "lcd.h"
#include <s3c2440.h>

void lcd0_init(void)
{
	//引脚
	GPCCON |= 0xffff;
	GPCCON = 0xaaaaaaaa;
	GPDUP  |= 0xffff;
	GPDCON = 0xaaaaaaaa;		
	//LCDCON1
	LCDCON1 |= (7 << 8) | (0x3 << 5) | (0xc << 1);

	//LCDCON2
	LCDCON2 |= (13 << 24) | (319 << 14);

	//LCDCON3
	LCDCON3 |= (80 << 19) | (239 << 8);

	//LCDCON5
	LCDCON5 |= (1 << 11) |(1 << 10) | (1 << 3);

	//LCDSADDR
	LCDSADDR1 | FRAMEBUFFER >> 1;
	LCDSADDR2 = (LCDSADDR1 & 0x1fffff) + 240*320;

	//最终使能
	LCDCON1 |= (0x1<< 0);
}

void display_point(int x, int y, unsigned short col)
{
	*((unsigned short *)FRAMEBUFFER+y*240+x) = col;
}

void clear(unsigned short col)
{
	int i = 0;
	int j = 0;
	for(i = 0; i < 320; i++)
	for(j = 0; j < 240; j++)
	display_point(j, i, col);
}


-----------------------------------------------------
     clear(0xf800);
	display_point(120, 160, 0);
	display_point(125, 160, 0);
	display_point(120, 165, 0);
	display_point(125, 165, 0);

十五:DMA

从内存空间操作的,所以是AHB

#include "dma.h"
#include <s3c2440.h>

void dma_init(void)
{
	DISRCC1 &= ~(0x3 << 0);	  	//AHB  增加
	DIDST1  &= ~(0x3 << 0);		//AHB  增加 
	
	DCON1 |= (1 << 31) | (1 << 30) | (1 << 27)
	       | (1 << 22) | (0x2 << 20);
	
	DSTAT1 = 0;		
}
void memcpy(unsigned long * dest,unsigned long * src,int len)
{
	unsigned char i = 0;
	DISRC1 &= ~(0x3fffffff << 0);
	DISRC1 = (unsigned long)src;
	DIDST1 &= ~(0x3fffffff << 0);
	DIDST1 = (unsigned long)dest;

	DCON1 &= ~(0xfffff << 0);
	DCON1 |= (len << 0);

	DMASKTRIG1 |= (1 << 1) | (1 << 0);

	while((DSTAT1 & (1 << 20)));
}
#include <REGX52.H> #include <string.h> unsigned int TIMER0_count; unsigned char hour,min,sec,day,month,year; sbit RS=P2^4; sbit RW=P2^5; sbit E=P2^6; void delay_ms(unsigned int ms) { unsigned int i,j; for(i=0;i<ms;i++) { for(j=0;j<123;j++); } } bit lcd_bz() { bit busy; RS=0; RW=1; E=1; busy=(P0&0x80); E=0; return busy; } void w_com(unsigned char com) { while(lcd_bz()); RS=0; RW=0; E=1; P0=com; delay_ms(1); E=0; } void w_dat(unsigned char dat) { while(lcd_bz()); RS=1; RW=0; E=1; P0=dat; delay_ms(1); E=0; } void lcd_ini() { delay_ms(30); w_com(0x38); delay_ms(5); w_com(0x0c); delay_ms(5); w_com(0x06); delay_ms(5); w_com(0x01); delay_ms(5); } void TIMER0_INT() { TMOD=0x01; TF0=0; TR0=1; TH0=64535/256; TL0=64535%256; ET0=1; EA=1; PT0=1; } void update_num() { w_com(0x80); w_dat(year/10+'0'); w_dat(year%10+'0'); w_dat('-'); w_dat(month/10+'0'); w_dat(month%10+'0'); w_dat('-'); w_dat(day/10+'0'); w_dat(day%10+'0'); w_com(0xc0); w_dat(hour/10+'0'); w_dat(hour%10+'0'); w_dat(':'); w_dat(min/10+'0'); w_dat(min%10+'0'); w_dat(':'); w_dat(sec/10+'0'); w_dat(sec%10+'0'); } void main() { sec=min=hour=0; month=day=1; year=23; TIMER0_INT(); lcd_ini(); update_num(); delay_ms(10); while (1) { if(sec >= 60) { sec = 0; min++; } if(min >= 60) { min = 0; hour++; } if(hour >= 24) { hour = 0; day++; } if(month == 2) { if((year % 4 == 0) && (day > 29)) { day = 1; month++; } else if((year % 4 != 0) && (day > 28)) { day = 1; month++; } } else if(month == 4 || month == 6 || month == 9 || month == 11) { if(day > 30) { day = 1; month++; } }
06-18
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值