/*----------------------------------------------------------*\ | PCD5544 Initialize | \*----------------------------------------------------------*/ void LCD_Init(void) { //PINSEL0 &= 0xEFFFFFFF; // 设置SPI管脚连接 PINSEL0 |= 0x20000000; // 设置SPI管脚连接 //PINSEL1 &= 0xFFFFFCFF; // 设置SPI管脚连接 PINSEL1 |= 0x00000100; // 设置SPI管脚连接 IODIR |= (1<<21)|(1<<13)|(1<<19); IOCLR = (1<<19); //SSPCCR = 0x08; // 设置SPI时钟分频 //SSPCR = 0x38; // 设置SPI接口模式,MSTR=1,CPOL=1,CPHA=1,LSBF=0 SSP_Init(); IOSET=(1<<19); IOCLR=(1<<21); IOCLR=(1<<13); //准备写指令 /* LCD_Write(32+1); //进入扩展指令 LCD_Write(128+38); //设置Vop,相当于亮度 LCD_Write(4+3); //设置温度系数,相当于对比度 LCD_Write(16 +3); // 设置偏置,这句要与不要的实际效果好像一样 LCD_Write(32+0); //进入基本指令 LCD_Write(12); //使能芯片活动/垂直寻址 */ LCD_Write(0x21);//初始化Lcd,功能设定使用扩充指令 LCD_Write(0xd0);//设定液晶偏置电压 LCD_Write(0x20);//使用基本指令 LCD_Write(0x0C);//设定显示模式,正常显示 IOSET=(1<<21); Delay(1); }
///---------------------------------------------------------- void LCD_Hundler(void){ switch(Segment){ case 1 : PORTC |= 0x07; LCD_Write(data_seg_1); LCD_D_1 = 0; KeyUpHundler(); ///---------------------------------------------- break; case 2 : PORTC |= 0x07; LCD_Write(data_seg_2); LCD_D_2 = 0; KeyDownHundler(); break; case 3 : PORTC |= 0x07; LCD_Write(data_seg_3); LCD_D_3 = 0; KeySelectHundler(); break; case 4 : PORTC |= 0x07; LED_Write(0x00); LED_ON_OFF = 0; KeyStartStopHundler(); LED_ON_OFF = 1; LED_Write(LED_DATA); break; case 5 : LED_ON_OFF = 0; break; case 6 : PORTC |= 0x07; LED_ON_OFF = 1; break; } Segment++; if(Segment > 6) Segment = 1; return; }
//******************************************* //*函数名称:void LCD_Init(void) * //*函数功能:并行初始化LCD * //*形式参数:无 * //*形参说明:无 * //*返回参数:无 * //*使用说明:无 * //******************************************* void LCD_Init(void) { LCD_CTRL_OUT(); #if PARALLEL == 1 #ifdef LCD_RST LCD_RST_LOW(); _delay_ms(10); LCD_RST_HIGH(); //RST = 1; //复位后拉高,停止复位 #endif #ifdef LCD_PSB LCD_PSB_HIGH(); //PSB = 1; //选择并行传输模式 #endif #else #ifdef LCD_RST LCD_RST_LOW(); _delay_ms(100); LCD_RST_HIGH(); //RST = 1; //复位后拉高,停止复位 #endif #ifdef LCD_PSB LCD_PSB_LOW(); //PSB = 0; //选择串并行传输模式 #endif #endif //#if PARALLEL == 1 LCD_Write(LCD_COMMAND,LCD_BASIC_FUNCTION); //基本指令动作 LCD_Write(LCD_COMMAND,LCD_CLEAR_SCREEN); //清屏,地址指针指向00H LCD_Write(LCD_COMMAND,0x06); //光标的移动方向 LCD_Write(LCD_COMMAND,0x0C); //开显示,关游标 }
static void LCD_Init (void) { LCD_E_IO = 0; LCD_RD_WR_IO = 0; LCD_DATA_TRIS = 0; LCD_RD_WR_TRIS = 0; LCD_RS_TRIS = 0; LCD_E_TRIS = 0; BSP_Dly(40000); LCD_RS_IO = 0; LCD_DATA_IO = 0x03; BSP_Dly(1); LCD_E_IO = 1; BSP_Dly(1); LCD_E_IO = 0; BSP_Dly(5); LCD_Write(0, 0x38); BSP_Dly(5); LCD_Write(0, 0x06); BSP_Dly(5); LCD_Write(0, 0x0C); BSP_Dly(5); LCD_Write(0, 0x01); BSP_Dly(2); }
void EnviaHistorico(){ LCD_Clear(); LCD_Write(" ENVIA ", 1); LCD_Write(" HISTORICO", 2); B16 cal; uint16_t mem_mes = MES1; uint8_t day[3]; uint8_t hour[3]; DADOMEDIDA hist; int ind_mes; for(ind_mes = 0; ind_mes < 6; ind_mes++) { mem_mes = mem_mes + (ind_mes*0x1173); cal = GetMesAno(mem_mes); int ler; for(ler = 0; ler < 744; ler++) { hist = LeSequencia((ind_mes*0x1173), ler); day[0] = hist.datetime[0]; day[1] = cal.byte[1]; day[2] = cal.byte[0]; hour[0] = hist.datetime[1]; hour[1] = hist.datetime[2]; hour[2] = hist.datetime[3]; Bluetooth_EnviaDados(hist.med.word, day, hour); } } Delay(1000); LCD_Clear(); }
void LCD_print(uint8_t num_bytes, uint8_t *array_name) { uint8_t idata index,character; if(num_bytes==0) { index=0; character=*(array_name+index); while(character!=0) { LCD_Write(DDRAM,character); DELAY_100us_T1(1); index++; character=*(array_name+index); } } else { for(index=0;index<num_bytes;index++) { character=*(array_name+index); LCD_Write(DDRAM,character); DELAY_100us_T1(1); } } }
void main(void) { uint8_t error_flag; LED3=0; UART_Init(); LCD_Init(); SPI_master_init(400000); // Set clock rate to that speed in Hz error_flag = SDcard_init(); while(1) { LED1 = 0; LED4 = 0; if(error_flag != NO_ERRORS) { LED4 = 0; } else { LED4 = 1; } delay_ms(1000); LED1 = 1; LED4 = 1; LCD_Write(COMMAND, LINE1); LCD_Print(16, "Coltons and Matt"); LCD_Write(COMMAND, LINE2); LCD_Print(15, "hews LCD Works!"); delay_ms(3000); LCD_Clear(); } }
void main(void) { initLCD(); while(1) { LCD_goto(2,0); LCD_num(hour); LCD_goto(2,2); LCD_Write(':',1);delay_ms(100); LCD_goto(2,3); LCD_num(min); LCD_goto(2,5); LCD_Write(':',1);delay_ms(100); LCD_goto(2,6); LCD_num(sec); sec++; delay_ms(500); if(sec==10){ sec=00; min++; if (min==10) {min=0; hour++; } } } }
void ImprimeStatusAgua() { if (aberta == 0x01) LCD_Write("AGUA OK", 3); if (aberta == 0x00) LCD_Write("FALTA DE AGUA", 3); }
/*----------------------------------------------------------*\ | PCD5544 goto x,y | \*----------------------------------------------------------*/ void LCD_GotoXY(unsigned char x, unsigned char y) { IOCLR = (1<<13); //准备写指令 IOCLR = (1<<21); LCD_Write(128+x); LCD_Write(64+y); IOSET=(1<<21); Delay(1); }
/** * Data transfer with the display is synchronized by sending a zero * byte 4 times consecutively * You should send this from time to time to keep the data * transfer in sync */ void LCD_SyncTransfer(void) { pause(10); LCD_Write(0x0000, 0x0000); LCD_Write(0x0000, 0x0000); LCD_Write(0x0000, 0x0000); LCD_Write(0x0000, 0x0000); pause(15); }
//********************************************************************************* //*函数名称:void LCD_DisplayStrings_WithAddress(unsigned char ucAdd,unsigned char code *p) * //*函数功能:在(文本区)ucAdd指定的位置显示一串字符(或是汉字或是ASCII或是两者混合) * //*形式参数:unsigned char ucAdd,unsigned char code *p * //*形参说明:指定的位置,要显示的字符串 * //*地址必须是:80H~87H,90H~97H,88H~8FH,98H~8FH * //*返回参数:无 * //*使用说明:使用之前要初始化液晶 * //********************************************************************************* void LCD_DisplayStrings_WithAddress(unsigned char ucAdd,const char *p) { unsigned char length; length = strlen(p); LCD_Write(LCD_COMMAND,LCD_BASIC_FUNCTION); //基本指令动作 LCD_DDRAM_AddressSet(ucAdd); for( ; length ; length -- ) LCD_Write(LCD_DATA, *(p++)); }
void LCD_goto(unsigned char row,unsigned char column) { if(row==1){ LCD_Write(0x80+column,0); // } else if(row==2){ LCD_Write(0xC0+column,0); } }
void LCD_Character(uint8 character) { uint16 index1; LCD_Write(LCD_DATA, EMPTY_COLUMN_DATA); for (index1 = 0 ; index1 < FONT_WIDTH ; index1++) LCD_Write(LCD_DATA, Fonts[character - OFFSET_FOR_ASCII][index1]); LCD_Write(LCD_DATA, EMPTY_COLUMN_DATA); }
void ResetMemoria() { LCD_Clear(); LCD_Write(" RESET", 1); LCD_Write(" MEMORIA", 2); ResetMem(); LCD_Clear(); }
void initLCD(void) { //PORT configuration TRISB = 0x00; TRISD=0x00; ////////////////// LCD_Write(0x38,0); delay_ms(1); LCD_Write(0x0c,0); //dispaly on , cursor blinking delay_ms(1); LCD_Write(0x01,0); // clear dispaly screen delay_ms(1); LCD_Write(0x06,0); // LCD_Write(0x0F,0); //blinking cursor delay_ms(1); LCD_clear(); LCD_goto(1,0); LCD_Write('C',1);delay_ms(100);LCD_Write('l',1);delay_ms(100); LCD_Write('o',1);delay_ms(100);LCD_Write('c',1);delay_ms(100); LCD_Write('k',1);delay_ms(100); }
void FechaValvula() { LCD_Clear(); CloseValve(); LCD_Write(" FECHA VALVULA", 0); LCD_Write("--------------------", 2); Delay(1000); LCD_Clear(); }
bool LCD_Init ( LCD display ) { lcd = display; /* * TODO: * The function should clear only the appropriate bits, not the whole PORT */ if ( lcd.PORT == &PORTA ) { TRISA = 0x00; } else if ( lcd.PORT == &PORTB ) { TRISB = 0x00; } else if ( lcd.PORT == &PORTC ) { TRISC = 0x00; } #if defined(_16F877) || defined(_16F877A) else if ( lcd.PORT == &PORTD ) { TRISD = 0x00; } else if ( lcd.PORT == &PORTE ) { TRISE = 0x00; } #endif else { return false; } // Give some time to the LCD to start function properly __delay_ms(20); // Send reset signal to the LCD LCD_Write(0x03); __delay_ms(5); LCD_Write(0x03); __delay_ms(16); LCD_Write(0x03); // Specify the data lenght to 4 bits LCD_Write(0x02); // Set interface data length to 8 bits, number of display lines to 2 and font to 5x8 dots LCD_Cmd(0x28); // Set cursor to move from left to right LCD_Cmd(0x06); LCD_Display(true, false, false); // Turn on display and set cursor off LCD_Clear(); return true; }
void AbreValvula() { LCD_Clear(); OpenValve(); LCD_Write(" ABRE VALVULA", 0); LCD_Write("---------/ /--------", 2); Delay(1000); LCD_Clear(); }
void LCD_Test(void) { u8 i,j; for(i=0;i<32;i++) { LCD_Write(0,0x80+i);LCD_Write(0,0x80); for(j=0;j<16;j++) LCD_Write(1,0xff); } }
void LCD_Disp (CPU_INT08U pos, CPU_CHAR *str) { LCD_Write(0, pos); /* Perform a control write setting the position */ BSP_Dly(5); if (*str) { do { LCD_Write(1, *str++); /* Write the string, 1 character at at time */ BSP_Dly(5); } while (*str); } }
/************************************************ * PlotPoint function * ************************************************/ int PlotPoint(int x, int y, int state) { if ((x < 0) || (x >= Scrn_W) || (y < 0) || (y >= Scrn_H)) // if sent a pixel not on the screen return(OUT_OF_RANGE); // return error LCD_SetAddr(x,y,x+2,y+2); LCD_Write(WRITE_RAM_CMD,CMD); // write memory write start command LCD_Write(((state>>8)&0x00FF),DAT); // write the first part of the color LCD_Write((state&0x00FF),DAT); // write the last part of the color return(SUCCESS); }
//***************************************************** //*函数名称:void LCD_GraphModeSet(unsigned char bSelect) * //*函数功能:打开或关闭绘图显示 * //*形式参数:unsigned char Select * //*形参说明:打开或关闭绘图显示的标志位,1打开,0关闭 * //*格式说明: * //* RS RW DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0 * //* 0 0 0 0 1 1 X RE G X * //* * //* RE:0,基本指令集 * //* RE:1,扩充指令集 * //* G :0,绘图显示OFF * //* G :1,绘图显示ON * //*返回参数:无 * //*使用说明:无 * //***************************************************** void LCD_GraphModeSet(unsigned char Select) { LCD_Write(LCD_COMMAND,LCD_EXTEND_FUNCTION); //扩展指令集 if(Select) { LCD_Write(LCD_COMMAND,LCD_GRAPH_ON); //打开绘图模式 } else { LCD_Write(LCD_COMMAND,LCD_GRAPH_OFF); //关闭绘图模式 } }
void LCD_Out(unsigned int DATA) { unsigned char A[4], i; for (i=0; i<4; i++) { A[i] = DATA % 16; DATA = DATA / 16; } LCD_Write(ascii(A[3])); LCD_Write(ascii(A[2])); LCD_Write(ascii(A[1])); LCD_Write(ascii(A[0])); }
void LCD_Out(unsigned int DATA, unsigned char N) { unsigned char A[5], i; for (i=0; i<5; i++) { A[i] = DATA % 10; DATA = DATA / 10; } for (i=5; i>0; i--) { if (i == N) LCD_Write('.'); LCD_Write(A[i-1] + '0'); } }
/****************************************************************** 名称:void LCD_DisChar(u8 Line,char *Hanzi) 功能:将输入的字符显示在12864上 调用:LCD_Write(); 入口参数说明: Line 为所要显示在的行数,若输入0则默认为紧随上一个地址写 ******************************************************************/ void LCD_DisChar(u8 Line,char *Hanzi) { u8 i; if(Line!=0) { LCD_Write(LCD_Flag_Cmd,Line); } i=0; while(Hanzi[i]!='\0') LCD_Write(LCD_Flag_Data,Hanzi[i++]); }
/****************************************************************** 名称:void LCD_WriteAddr(u8 x ,u8 y) 功能:在制定地址显示数字 入口参数说明: x取值为1-4,y取值为1-8 ******************************************************************/ void LCD_WriteAddr(u8 x ,u8 y) { if(x>=1&&x<=4&&y>=1&&y<=8) { switch(x) { case 1: LCD_Write(0,0x80+y-1); break; case 2: LCD_Write(0,0x90+y-1); break; case 3: LCD_Write(0,0x88+y-1); break; case 4: LCD_Write(0,0x98+y-1); break; } } }
//****************************************************************************** //*函数名称:void LCD_ImgDisplayCharacter(unsigned char x,unsigned char y,unsigned char code *img) * //*函数功能:使用绘图的方法,在(x,y)处画一个16*16点阵的图案,也可以是字符 * //*形式参数:unsigned char x,unsigned char y,unsigned char code *img * //* x取值范围:0~7 * //* y取值范围:0~31 (针对CM12864-12型液晶) * //*形参说明:坐标水平位置,坐标垂直位置,要显示的图形 * //*液晶屏坐标说明: * //* ________________128个像素______________________ * //* |(0,0) (7,0)| * //* | | * //* 64 | | * //* 个 |(0,31) (7,31)| * //* 像 |(8,0) (15,0)| * //* 素 | | * //* | | * //* |(8,31) (15,31)| * //* |______________________________________________| * //* * //*返回参数:无 * //*使用说明:此函数适用于CM12864-12型液晶 * //****************************************************************************** void LCD_ImgDisplayCharacter(unsigned char x,unsigned char y,unsigned char *img) { unsigned char i; LCD_GraphModeSet(0x00); //先关闭图形显示功能 LCD_Write(LCD_COMMAND,LCD_EXTEND_FUNCTION); for(i=0;i<16;i++) { LCD_GDRAM_AddressSet(0x80+y+i); LCD_GDRAM_AddressSet(0x80+x); LCD_Write(LCD_DATA,img[i*2]); LCD_Write(LCD_DATA,img[i*2+1]); } LCD_GraphModeSet(0x01); //最后打开图形显示功能 }
void LCD_WriteBmp(u8 *puts) { // u16 x=0; u8 i,j; LCD_Write(LCD_Flag_Cmd,LCD_COM_PLOT_OFF); //扩展指令集动作,绘图显示OFF for(i=0;i<32;i++) { LCD_Write(LCD_Flag_Cmd,0x80|i); //列32行,双屏结构中上半屏 y 1-32 LCD_Write(LCD_Flag_Cmd,0x80); //X地址坐标,自动加1. x 1-8 for(j=0;j<16;j++) //16*8=256 LCD_Write(LCD_Flag_Data,0xf0); } for(i=0;i<32;i++) { LCD_Write(LCD_Flag_Cmd,0x80|i); LCD_Write(LCD_Flag_Cmd,0x88); //下半屏 for(j=0;j<16;j++) LCD_Write(LCD_Flag_Data,0xf0); } LCD_Write(LCD_Flag_Cmd,LCD_COM_PLOT_ON); //扩展指令集动作,绘图显示ON }
void LCD_Init(void) { LCD_SetBits(CS); delay_ms(100); LCD_Write(LCD_Flag_Cmd,0x30); //8 位介面,基本指令集 delay_ms(10); LCD_Write(LCD_Flag_Cmd,0x30); delay_ms(10); LCD_Write(LCD_Flag_Cmd,0x0c); //显示打开,光标关,反白关 delay_ms(10); LCD_Write(LCD_Flag_Cmd,0x01); //清屏,将DDRAM的地址计数器归零 delay_ms(10); }