/****************************************************************************** * 函数原型: -LCD_PutGraphic * 函数功能: * 输入参数: * 输出参数: * 编写日期: 2014/04/13, ChenxianLong create this function ******************************************************************************/ void LCD_PutGraphic(unsigned char code *img) { int i,j; //显示上半屏内容设置 for(i=0;i<32;i++) { Write_Cmd(0x80 + i); //SET 垂直地址 VERTICAL ADD Write_Cmd(0x80); //SET 水平地址 HORIZONTAL ADD for(j=0;j<16;j++) { Write_Data(*img); img++; } } //显示下半屏内容设置 for(i=0;i<32;i++) { Write_Cmd(0x80 + i); //SET 垂直地址 VERTICAL ADD Write_Cmd(0x88); //SET 水平地址 HORIZONTAL ADD for(j=0;j<16;j++) { Write_Data(*img); img++; } } }
/****************************************************************************** * CGRAM: * 函数原型: - * 函数功能: * 输入参数: * 输出参数: * 编写日期: 2014/04/13, ChenxianLong create this function ******************************************************************************/ void CGRAM() { int i; Write_Cmd(0x30); Write_Cmd(0x40); for(i=0;i<16;i++) { // Write_Data(user16x16[i*2]); // Write_Data(user16x16[i*2+1]); } }
/****************************************************************************** * DisplayCGRAM: * 函数原型: - * 函数功能: * 输入参数: * 输出参数: * 编写日期: 2014/04/13, ChenxianLong create this function ******************************************************************************/ void DisplayCGRAM(unsigned char x,unsigned char y) { switch(y) { case 1: Write_Cmd(0x80+x);break; case 2: Write_Cmd(0x90+x);break; case 3: Write_Cmd(0x88+x);break; case 4: Write_Cmd(0x98+x);break; default:break; } Write_Data(00); Write_Data(00); }
/****************************************************************************** * Init_ST7920: * 函数原型: - * 函数功能: * 输入参数: * 输出参数: * 编写日期: 2014/04/13, ChenxianLong create this function ******************************************************************************/ void Init_ST7920() { DelaynMs(10); Write_Cmd(0x30); //选择基本指令集 DelayUs2x(50); //延时大于100us Write_Cmd(0x30); //选择8bit数据流 DelayUs2x(20); //延时大于37us Write_Cmd(0x0c); //开显示(无游标、不反白) DelayUs2x(50); //延时大于100us Write_Cmd(0x01); //清除显示,并且设定地址指针为00H DelaynMs(15); //延时大于10ms Write_Cmd(0x06); //指定在资料的读取及写入时,设定游标的移动方向及指定显示的移位,光标从右向左加1位移动 DelayUs2x(50); //延时大于100us }
/****************************************************************************** * LCD_PutString: * 函数原型: - * 函数功能: * 输入参数: * 输出参数: * 编写日期: 2014/04/13, ChenxianLong create this function ******************************************************************************/ void LCD_PutString(unsigned char x,unsigned char y,unsigned char code *s) { switch(y) { case 1: Write_Cmd(0x80+x);break; case 2: Write_Cmd(0x90+x);break; case 3: Write_Cmd(0x88+x);break; case 4: Write_Cmd(0x98+x);break; default:break; } while(*s>0) { Write_Data(*s); s++; DelayUs2x(250); } }
void Write_Cmd_Data (unsigned char x,unsigned int y) { unsigned char m,n; m=y>>8; n=y; Write_Cmd(0x00,x); Write_Data(m,n); }
static void clear( color c = white ){ int d = from_color( c ); LCD_SetCursor( 0x00, 0x0000 ); Write_Cmd( 0x22 ); // write RAM prepare for( int index = 0; index < 76800; index++ ){ Write_Dat( d ); } }
void LCD_SetPos(unsigned int x0,unsigned int x1,unsigned int y0,unsigned int y1) { Write_Cmd_Data(0x50,x0); // Horizontal GRAM Start Address Write_Cmd_Data(0x51,x1); // Horizontal GRAM End Address Write_Cmd_Data(0x52,y0); // Vertical GRAM Start Address Write_Cmd_Data(0x53,y1); // Vertical GRAM Start Address Write_Cmd_Data(0x20,x0); // GRAM horizontal Address Write_Cmd_Data(0x21,y0); // GRAM Vertical Address Write_Cmd (0x00,0x22); // 0x0022,Start to Write Data to GRAM }
/***************************************************************************** ** �������: LCD_ReadReg ** ��������: ��ָ�� ** �� ����: Dream ** �ա� ��: 2010��12��06�� *****************************************************************************/ uint16_t LCD_ReadReg(uint16_t LCD_Reg) { uint16_t temp; Write_Cmd(LCD_Reg); //д��Ҫ���ļĴ����� GPIOB->CRH = (GPIOB->CRH & 0x00000000) | 0x44444444; //���˿ڸ�8λ���ó����� GPIOC->CRL = (GPIOC->CRL & 0x00000000) | 0x44444444; //���˿ڵ�8λ���ó����� LCD_CS = 0; LCD_RS = 1; LCD_RD = 0; temp = ((GPIOB->IDR&0xff00)|(GPIOC->IDR&0x00ff)); //��ȡ���(���Ĵ���ʱ,������Ҫ��2��) LCD_RD = 1; LCD_CS = 1; GPIOB->CRH = (GPIOB->CRH & 0x00000000) | 0x33333333; //�ͷŶ˿ڸ�8λΪ��� GPIOC->CRL = (GPIOC->CRL & 0x00000000) | 0x33333333; //�ͷŶ˿ڵ�8λΪ��� return temp; }
/***************************************************************************** ** �������: LCD_Write_Reg ** ��������: дָ���� ** �� ����: Dream ** �ա� ��: 2010��12��06�� *****************************************************************************/ void LCD_WriteReg(uint16_t LCD_Reg,uint16_t LCD_Dat) { Write_Cmd(LCD_Reg); Write_Dat(LCD_Dat); }
static color pixel_read( vector p ){ LCD_SetCursor( p.x_get(), p.y_get() ); Write_Cmd( 0x22 ); // write RAM prepare return to_color( LCD_ReadDat() ); }
static void pixel_write( vector p, color c ){ LCD_SetCursor( p.x_get(), p.y_get() ); Write_Cmd( 0x22 ); // write RAM prepare Write_Dat( from_color( c )); }
static int LCD_Read_Reg( int reg ){ Write_Cmd( reg ); return LCD_ReadDat(); }
static void LCD_WriteReg( int reg, int data ){ Write_Cmd( reg ); Write_Dat( data ); }
/****************************************************************************** * ClrScreen: * 函数原型: - * 函数功能: * 输入参数: * 输出参数: * 编写日期: 2014/04/13, ChenxianLong create this function ******************************************************************************/ void ClrScreen() { Write_Cmd(0x01); DelaynMs(15); }
/***************************************************************************** ** �������: LCD_WriteRAM_Prepare ** ��������: Щ�� ** �� ����: Dream ** �ա� ��: 2010��12��06�� *****************************************************************************/ void LCD_WriteRAM_Prepare() { Write_Cmd(R34); }
/***************************************************************************** ** �������: LCD_DrawPoint ** ��������: дһ���� ** �� ����: Dream ** �ա� ��: 2010��12��06�� *****************************************************************************/ void LCD_DrawPoint(uint16_t x,uint16_t y) { LCD_SetCursor(x,y);//���ù��λ�� Write_Cmd(R34);//��ʼд��GRAM Write_Dat(POINT_COLOR); }
/****************************************************************************** * 函数原型: -SetGraphicMode * 函数功能: * 输入参数: * 输出参数: * 编写日期: 2014/04/13, ChenxianLong create this function ******************************************************************************/ void SetGraphicMode() { Write_Cmd(0x36); //选择8bit数据流 图形模式 DelayUs2x(20); }