|
楼主 |
发表于 2008-10-11 13:48:48
|
显示全部楼层
简单程序
----------------------------------------
/*
lcd.h
*/
#ifndef __LCD_H__
#define __LCD_H__
//p0.0~p0.7
//p0.2-r
//p0.3-g
//p0.4-b
#define RGB_OUT IODIR |= 0x000000ff;
#define RGB_DATA(x) {IOCLR = 0x000000ff;\
IOSET = x<<4;}
#define VS_OUT IODIR |= 0x00000400 //p0.10
#define VS_1 IOSET = 0x00000400
#define VS_0 IOCLR = 0x00000400
#define HS_OUT IODIR |= 0x00000800 //p0.11
#define HS_1 IOSET = 0x00000800
#define HS_0 IOCLR = 0x00000800
#define CK_OUT IODIR |= 0x00001000 //p0.12
#define CK_1 IOSET = 0x00001000
#define CK_0 IOCLR = 0x00001000
#define DISP_OUT IODIR |= 0x00002000 //p0.13
#define DISP_1 IOSET = 0x00002000
#define DISP_0 IOCLR = 0x00002000
#define VDD_EN_OUT IODIR |= 0x00000100 //p0.8
#define VDD_EN_1 IOSET = 0x00000100
#define VDD_EN_0 IOCLR = 0x00000100
#define CK_10 {CK_1; CK_0; CK_1; CK_0; CK_1; CK_0; CK_1; CK_0; CK_1; CK_0;\
CK_1; CK_0; CK_1; CK_0; CK_1; CK_0; CK_1; CK_0; CK_1; CK_0;}
#define CK_100 {CK_10; CK_10; CK_10; CK_10; CK_10; CK_10; CK_10; CK_10; CK_10; CK_10;}
#define NO_DIS_DATA 0x00
//x=0-479, y=0-271
extern void Dis(unsigned int x, unsigned int y, unsigned int x_wide, unsigned int y_hight, const unsigned char *p);
extern void Lcd_Init(void);
#endif
----------------------------------------------------------
/*
lcd.c
*/
#include "NXP/iolpc210x.h" /* Defines Special function registers */
#include "intrinsics.h"
#include "lcd.h"
#include "EasyARM2104.h"
void Delay(void){
unsigned long i;
for(i=0; i<10000; i++){
;//_NOP();
}
}
unsigned char dis_buf[480];
void Lcd_Line(void){
unsigned int i;
//hsync
HS_0;
//41 ck
CK_10; CK_10; CK_10; CK_10;
CK_1; CK_0;
HS_1;
//2 ck
CK_1; CK_0;
CK_1; CK_0;
//480 ck
for(i=0; i<480; i++){
CK_0;
RGB_DATA(dis_buf);
CK_1;
}
CK_0;
//2 ck
CK_1; CK_0;
CK_1; CK_0;
}
//x=0-479, y=0-271
void Dis(unsigned int x, unsigned int y, unsigned int x_wide, unsigned int y_hight, const unsigned char *p){
unsigned int i;
unsigned int j;
unsigned char k;
//vsync
VS_0;
//10 line
Lcd_Line(); Lcd_Line();
Lcd_Line(); Lcd_Line();
Lcd_Line(); Lcd_Line();
Lcd_Line(); Lcd_Line();
Lcd_Line(); Lcd_Line();
VS_1;
//2 line
Lcd_Line();
Lcd_Line();
//272 line
for(j=0; j<272; j++){
if((j>=y) && (j<(y+y_hight))){
//480dot
for(i=0; i<480; i++){
if((i>=x) && (i<(x+x_wide ))){
k = *p++; //r
//R3G2B3->R1G1B1
dis_buf = 0;
if((k & 0x07)>= 0x04) //B3
dis_buf = 0x04;
if((k & 0x18)>= 0x10) //G2
dis_buf |= 0x02;
if((k & 0xe0)>= 0x80)
dis_buf |= 0x01; //R3
}
else
dis_buf = NO_DIS_DATA;
}
}
else{
for(i=0; i<480; i++)
dis_buf = NO_DIS_DATA;
}
Lcd_Line();
}
//2 line
Lcd_Line();
Lcd_Line();
//disp
DISP_1;
}
void Lcd_Init(void){
VDD_EN_OUT;
VDD_EN_0;
DISP_OUT;
DISP_0;
RGB_OUT;
RGB_DATA(0x00);
VS_OUT;
VS_0;
HS_OUT;
HS_0;
CK_OUT;
CK_0;
VDD_EN_1;
Delay();
Delay();
Delay();//>50ms
}
---------------------------------------
/*
main.c
*/
#include "NXP/iolpc210x.h" /* Defines Special function registers */
#include "intrinsics.h"
#include "bmp.h"
#include "lcd.h"
#include "EasyARM2104.h"
void Init(void){
__disable_interrupt();
PINSEL0 = 0x00000000;
PINSEL1 = 0x00000000;
//ports
KEY1_IN;
KEY2_IN;
KEY3_IN;
KEY4_IN;
KEY5_IN;
KEY6_IN;
Lcd_Init();
//PLL
//1.set
// PLLCFG = 0x60; //0 11 00000 = *1,*16
// PLLCFG = 0x41; //0 10 00001 = *2,*8
// PLLCFG = 0x42; //0 10 00010 = *3,*8
// PLLCFG = 0x43; //0 01 00011 = *4,*4
// PLLCFG = 0x44; //0 01 00100 = *5,*4
// PLLCFG = 0x45; //0 01 00101 = *6,*4
// PLLCFG = 0x06; //0 00 00110 = *7,*2
// PLLCFG = 0x07; //0 00 00110 = *8,*2
PLLCFG = 0x08; //0 00 00110 = *9,*2
// PLLCFG = 0x09; //0 00 01001 = *10,*2
PLLFEED = 0xaa; PLLFEED = 0x55;
//2.en
PLLCON = 0x01; //PLL使能
PLLFEED = 0xaa; PLLFEED = 0x55;
//3.lock?
while((PLLSTAT & 0x00000400) == 0x00000000); //bit10(PLL LOCK)
//4.con
PLLCON |= 0x02; //PLL连接
PLLFEED = 0xaa; PLLFEED = 0x55;
//system
MAMCR = 0x00; //MAM控制寄存器
//MAMTIM = 0x09; //MAM时序寄存器
MAMTIM = 3/*2*/;
MAMCR = 0x02;
MEMMAP = 0x01; //存储器映射控制寄存器
//MEMMAP = 0x02;
PCON = 0x00; //功率控制寄存器(睡眠)
PCONP = 0x00000000; //外设功率控制寄存器(模块关闭)
// VPBDIV = 0x00; //VPB分频器寄存器1/4
VPBDIV = 0x01; //1:1
// VPBDIV = 0x02; // 1/2
EXTINT = 0x00; //外部中断标志寄存器
EXTWAKE = 0x00; //外部中断唤醒寄存器
}
void main(void){
unsigned char i;
unsigned char j=20;
Init();
while(1){
if(KEY1_STATE == 0)
j=50;
if(KEY2_STATE == 0)
j=80;
if(i <= j)
Dis(10, 10, 122, 96, &(I_F_U[0][0]));
else if(i <= j*2)
Dis(150, 150, 121, 96, &(shazhu[0][0]));
if(++i>= j*3)
i=0;
}
} |
|