📄 lcdac1.c
字号:
uint16_t Cycles = 0; for (uint16_t Temp16 = Value ; Temp16 > 256 ; Temp16 -= 256) Cycles++; return (Value - (Cycles<<8)); }uint8_t LCD__vGetDigit(const uint16_t Value, const uint8_t NrDigit){ uint8_t CyclesUp = 0; uint8_t CyclesVal = 0; uint16_t Divider = 1; for (uint16_t i = 0 ; i < NrDigit ; i++) Divider = Divider*10; for (uint16_t Temp16 = Value ; Temp16 > Divider*10 ; Temp16 -= Divider*10) CyclesUp++; for (uint16_t Temp16 = Value ; Temp16 > Divider ; Temp16 -= Divider) CyclesVal++; return (CyclesVal - CyclesUp*10 + 16); // 16 positions offset for numbers}void LCD__vPutChar (uint8_t XPos, uint8_t YPos, uint8_t CharNr){ uint16_t Position; for (uint8_t i = 0 ; i < 8 ; i++) { Position = (YPos * 8 * 30) + (30 * i) + XPos; // YPos = Nr rand char, XPos = Poz. char in raw LCD__vWriteBytes (LCD_nSetCurLAddr, LCD__vGetLowByte (Position)); LCD__vWriteBytes (LCD_nSetCurHAddr, LCD__vGetHighByte (Position)); LCD__vWriteCtrl (LCD_nWriteData); LCD__vWriteData (pgm_read_byte(&FontLookupTable [CharNr][i])); }}void LCD_vPrintText (uint8_t Valoare){ LCD__vPutChar (0, 8, LCD__vGetDigit(Valoare+1, 2)); LCD__vPutChar (1, 8, LCD__vGetDigit(Valoare+1, 1)); LCD__vPutChar (2, 8, LCD__vGetDigit(Valoare+1, 0));}void LCD_vPrintLogo (void){ LCD__vPutChar (0, 0, 'e'-32); LCD__vPutChar (1, 0, 'O'-32); LCD__vPutChar (2, 0, 's'-32); LCD__vPutChar (3, 0, ' '-32); LCD__vPutChar (0, 1, 'c'-32); LCD__vPutChar (1, 1, 'o'-32); LCD__vPutChar (2, 1, 'p'-32); LCD__vPutChar (3, 1, 'e'-32); LCD__vPutChar (0, 3, 'v'-32); LCD__vPutChar (1, 3, 'e'-32); LCD__vPutChar (2, 3, 'r'-32); LCD__vPutChar (3, 3, '.'-32); LCD__vPutChar (0, 4, '1'-32); LCD__vPutChar (1, 4, '.'-32); LCD__vPutChar (2, 4, '0'-32); LCD__vPutChar (3, 4, ' '-32); LCD__vPutChar (0, 6, '-'-32); LCD__vPutChar (1, 6, '-'-32); LCD__vPutChar (2, 6, '-'-32); LCD__vPutChar (3, 6, '-'-32);}void LCD__vBusyWait (void){ LCD_u8DataDdr &= (~(1<<LCD_nBusyFlag)); /* Set BF pin as input */ LCD_u8DataPort &= (~(1<<LCD_nBusyFlag)); /* No pullup for BF */ LCD_u8CtrlPort |= (1<<LCD_nCtrlRS); /* Set RegisterSelect bit on 1 */ LCD_u8CtrlPort |= (1<<LCD_nCtrlRW); /* Set ReadWrite bit on 1 */ while (LCD_u8DataPin & (1<<LCD_nBusyFlag)) /* test if busy flag is 0 */ { LCD_u8CtrlPort|=(1<<LCD_nCtrlE); LCD_u8CtrlPort &= (~(1<<LCD_nCtrlE)); } LCD_u8DataDdr |= (1<<LCD_nBusyFlag); /* Set BF pin as output */}void LCD__vWriteCtrl(uint8_t u8Control){ LCD__vBusyWait (); /* Wait on BusyFlag */ LCD_u8DataPort = u8Control; /* Output byte to port */ /* Already performed by BusyWait LCD_u8CtrlPort |= (1<<LCD_nCtrlRS); Set RegisterSelect bit on 1 */ LCD_u8CtrlPort &= (~(1<<LCD_nCtrlRW)); /* Clear ReadWrite bit on 0 */ LCD_u8CtrlPort |=(1<<LCD_nCtrlE); /* Set: E = 1 */ LCD_u8CtrlPort &= (~(1<<LCD_nCtrlE)); /* Clear: E = 0 */}void LCD__vWriteData(uint8_t u8Data){ LCD_u8DataPort = u8Data; /* Output data to port */ LCD_u8CtrlPort &= (~(1<<LCD_nCtrlRS)); /* Clear RegisterSelect bit to 0 */ LCD_u8CtrlPort &= (~(1<<LCD_nCtrlRW)); /* Clear ReadWrite bit to 0 */ LCD_u8CtrlPort |= (1<<LCD_nCtrlE); /* Set: E = 1 */ LCD_u8CtrlPort &= (~(1<<LCD_nCtrlE)); /* Clear: E = 0 */ TIM_vDelay(2);}void LCD__vWriteDataFast(uint8_t u8Data)/* Always use after LCD__vPrepareWriteDataFast(), to speed up repetitive WriteData operations */{ LCD_u8DataPort = u8Data; /* Output data to port */ LCD_u8CtrlPort |= (1<<LCD_nCtrlE); /* Set: E = 1 */ LCD_u8CtrlPort &= (~(1<<LCD_nCtrlE)); /* Clear: E = 0 */ TIM_vDelay(2);}void LCD__vWriteBytes(uint8_t u8Control,uint8_t u8Data){ LCD__vBusyWait (); /* Wait on BusyFlag */ LCD_u8DataPort = u8Control; /* Output byte to port */ /* Already performed by BusyWait LCD_u8CtrlPort |= (1<<LCD_nCtrlRS); Set RegisterSelect bit on 1 */ LCD_u8CtrlPort &= (~(1<<LCD_nCtrlRW)); /* Clear ReadWrite bit on 0 */ LCD_u8CtrlPort |=(1<<LCD_nCtrlE); /* Set: E = 1 */ LCD_u8CtrlPort &= (~(1<<LCD_nCtrlE)); /* Clear: E = 0 */ LCD_u8DataPort = u8Data; /* Output data to port */ LCD_u8CtrlPort &= (~(1<<LCD_nCtrlRS)); /* Clear RegisterSelect bit to 0 */ LCD_u8CtrlPort |= (1<<LCD_nCtrlE); /* Set: E = 1 */ LCD_u8CtrlPort &= (~(1<<LCD_nCtrlE)); /* Clear: E = 0 */ TIM_vDelay(2);}uint8_t LCD__u8GetYValue (uint8_t RowNr, uint8_t ByteNr){ uint8_t Result = 0; if (((*(pu8Buffer+ByteNr+1) >= RowNr)&&(*(pu8Buffer+ByteNr)<=RowNr)) || ((*(pu8Buffer+ByteNr+1) <= RowNr)&&(*(pu8Buffer+ByteNr)>=RowNr))) { Result |= 0x01; } if (((*(pu8Buffer+ByteNr+2) >= RowNr)&&(*(pu8Buffer+ByteNr+1)<=RowNr)) || ((*(pu8Buffer+ByteNr+2) <= RowNr)&&(*(pu8Buffer+ByteNr+1)>=RowNr))) { Result |= 0x02; } if (((*(pu8Buffer+ByteNr+3) >= RowNr)&&(*(pu8Buffer+ByteNr+2)<=RowNr)) || ((*(pu8Buffer+ByteNr+3) <= RowNr)&&(*(pu8Buffer+ByteNr+2)>=RowNr))) { Result |= 0x04; } if (((*(pu8Buffer+ByteNr+4) >= RowNr)&&(*(pu8Buffer+ByteNr+3)<=RowNr)) || ((*(pu8Buffer+ByteNr+4) <= RowNr)&&(*(pu8Buffer+ByteNr+3)>=RowNr))) { Result |= 0x08; } if (((*(pu8Buffer+ByteNr+5) >= RowNr)&&(*(pu8Buffer+ByteNr+4)<=RowNr)) || ((*(pu8Buffer+ByteNr+5) <= RowNr)&&(*(pu8Buffer+ByteNr+4)>=RowNr))) { Result |= 0x10; } if (((*(pu8Buffer+ByteNr+6) >= RowNr)&&(*(pu8Buffer+ByteNr+5)<=RowNr)) || ((*(pu8Buffer+ByteNr+6) <= RowNr)&&(*(pu8Buffer+ByteNr+5)>=RowNr))) { Result |= 0x20; } if (((*(pu8Buffer+ByteNr+7) >= RowNr)&&(*(pu8Buffer+ByteNr+6)<=RowNr)) || ((*(pu8Buffer+ByteNr+7) <= RowNr)&&(*(pu8Buffer+ByteNr+6)>=RowNr))) { Result |= 0x40; } if (((*(pu8Buffer+ByteNr+8) >= RowNr)&&(*(pu8Buffer+ByteNr+7)<=RowNr)) || ((*(pu8Buffer+ByteNr+8) <= RowNr)&&(*(pu8Buffer+ByteNr+7)>=RowNr))) { Result |= 0x80; } return (Result);}void LCD_vPrintString (void){ LCD__vPutChar (0, 10, TIM__stTimeBase[u8IndexTime].sText[0]-32); LCD__vPutChar (1, 10, TIM__stTimeBase[u8IndexTime].sText[1]-32); LCD__vPutChar (2, 10, TIM__stTimeBase[u8IndexTime].sText[2]-32); LCD__vPutChar (0, 11, TIM__stTimeBase[u8IndexTime].sText[3]-32); LCD__vPutChar (1, 11, TIM__stTimeBase[u8IndexTime].sText[4]-32); LCD__vPutChar (2, 11, TIM__stTimeBase[u8IndexTime].sText[5]-32); /* /div */ LCD__vPutChar (0, 12, '/'-32); LCD__vPutChar (1, 12, 'd'-32); LCD__vPutChar (2, 12, 'i'-32); LCD__vPutChar (3, 12, 'v'-32);}void LCD_vInitScreen (void){ LCD_u8DataDdr = 0xFF; /* LCD data port as output */ LCD_u8DataPort = 0x00; /* Data output is 0x00 */ LCD_u8CtrlDdrRESET |= (1<<LCD_nCtrlRESET); /* Set REST pin as output */ LCD_u8CtrlDdr |= (1<<LCD_nCtrlRS); /* Register select as output */ LCD_u8CtrlDdr |= (1<<LCD_nCtrlRW); LCD_u8CtrlDdr |= (1<<LCD_nCtrlE); LCD_u8CtrlPortRESET &= (~(1<<LCD_nCtrlRESET)); /* RESET active */ TIM_vDelay(7); LCD_u8CtrlPortRESET |= (1<<LCD_nCtrlRESET); /* RESET inactive */ TIM_vDelay(100); LCD__vWriteBytes (LCD_nSetLcdMode, 0x32); // SetGraphic mode LCD__vWriteBytes (LCD_nSetChPitch, 0x77); // 8 bits data LCD__vWriteBytes (LCD_nSetCharNum, 0x1d); // 29 chars per line LCD__vWriteBytes (LCD_nSetTimeDivs, 0x7f); // duty ratio = 128 LCD__vWriteBytes (LCD_nSetCurPos, 0x07); // cursor position = 0 LCD__vWriteBytes (LCD_nSetHomLAddr, 0x00); // home adress low = 0 LCD__vWriteBytes (LCD_nSetHomHAddr, 0x00); // home adress high = 0 LCD__vWriteBytes (LCD_nSetCurLAddr, 0x00); // cursor adress low = 0 LCD__vWriteBytes (LCD_nSetCurHAddr, 0x00); // cursor adress high = 0}void LCD_vClearScreen (void){ LCD__vWriteBytes (LCD_nSetCurLAddr, 0x00); // cursor adress low = 0 LCD__vWriteBytes (LCD_nSetCurHAddr, 0x00); // cursor adress high = 0 LCD__vWriteCtrl (LCD_nWriteData); // write data command for(uint16_t i=0; i<240*128/8; i++) { LCD__vWriteData (0x00); }}void LCD_vPrintTrigger(uint8_t u8TrigLev){ uint16_t res; uint8_t j; for (j = 0; j < 127; j++) { res =j*30+4; LCD__vWriteBytes(LCD_nSetCurLAddr,res); LCD__vWriteBytes(LCD_nSetCurHAddr,res>>8); LCD__vWriteCtrl (LCD_nWriteData); if (j == (u8TrigLev -1)) { LCD__vWriteData (0xB8); } else if (j == u8TrigLev) { LCD__vWriteData (0x08); } else if (j == (u8TrigLev + 1)) { LCD__vWriteData (0xB8); } else { LCD__vWriteData (0xC0); } u8TrigSemaphore = 0; }}/* Description: draws the trace from memory using the intersection between samples and cursor. Parses entire screen and overlaps the background bitmap to trace information */void LCD_vPrintSignal (void){ uint8_t j; uint8_t i; uint8_t n; for(i=0; i<127; i++) { LCD__vWriteBytes (LCD_nSetCurLAddr, pgm_read_byte(&CursorPrintPosition [i][1])); if (pgm_read_byte(&CursorPrintPosition [i][0]) != pgm_read_byte(&CursorPrintPosition [i-1][0])) { LCD__vWriteBytes(LCD_nSetCurHAddr, pgm_read_byte(&CursorPrintPosition [i][0])); } LCD__vWriteCtrl (LCD_nWriteData); n = 0; LCD__vPrepareWriteDataFast(); for(j = 5; j < 30; j++) { LCD__vWriteDataFast ((pgm_read_byte(&Grid[i][j])) | (LCD__u8GetYValue (i, n))); n += 8; } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -