Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- LCD 128x64 ST7920, Serial Mode
- Pinout:
- - GND = 5V
- - VCC = 5V
- - RS (CS) = D2 (or 5V)
- - R/W (SID) = D4
- - E (SCLK) = D5
- - PSB = GND
- - RST = 5V (or None)
- - BLA = 5V
- - BLK = GND
- */
- //! Choose PIN
- #define CS 2
- #define SID 4
- #define SCLK 5
- //! Choose DELAY
- //- Not use delay
- #define DELAY
- //- Use delay
- //#define DELAY delayMicroseconds(0)
- //! Choose CS_INIT, CS_ON, and CS_OFF
- //- Use CS
- //#define CS_INIT pinMode(CS, OUTPUT); digitalWrite(CS, LOW);
- //#define CS_ON digitalWrite(CS, HIGH); DELAY;
- //#define CS_OFF digitalWrite(CS, LOW); DELAY;
- //- Not use CS (#define CS no problem)
- #define CS_INIT
- #define CS_ON
- #define CS_OFF
- //! How to use:
- // LCD_init();
- // LCD_gotoYX(uint8_t y, uint8_t x); // Goto address y = 0.63, x = 0..7
- // LCD_word(uint16t d); // Set 16-bit pixels on address
- //! Ready?
- void LCD_init(){
- CS_INIT;
- pinMode(SID, OUTPUT);
- digitalWrite(SID, LOW);
- pinMode(SCLK, OUTPUT);
- digitalWrite(SCLK, LOW);
- delay(3);
- LCD_send(0, 48);
- LCD_send(0, 48);
- LCD_send(0, 12);
- LCD_send(0, 52);
- LCD_send(0, 52);
- LCD_send(0, 54);
- }
- void LCD_sid(uint8_t sid){
- digitalWrite(SID, sid ? HIGH : LOW);
- DELAY;
- digitalWrite(SCLK, HIGH);
- DELAY;
- digitalWrite(SCLK, LOW);
- DELAY;
- }
- void LCD_bits(uint8_t d){
- for (uint8_t i = 0x80; i; i >>= 1)
- LCD_sid(d & i);
- }
- void LCD_send(uint8_t rs, uint8_t d){
- CS_ON;
- LCD_bits( 0xF8 | ( rs << 1 ) );
- LCD_bits(d & 0xF0);
- LCD_bits(d << 4);
- CS_OFF;
- }
- void LCD_gotoYX(uint8_t y, uint8_t x){
- // y = 0.63, x = 0..7
- // ubah jadi
- // y = 0..31, x = 0..15
- LCD_send( 0, 0x80 | ( y & 31 ) );
- LCD_send( 0, 0x80 | x | (y >> 5 << 3));
- }
- void LCD_word(uint16_t d){
- LCD_send(1, d >> 8);
- LCD_send(1, d);
- }
- void LCD_byte(uint8_t d){
- LCD_send(1, d);
- }
- //! Ready!
- void setup() {
- LCD_init();
- }
- void loop() {
- for (uint8_t y = 0; y < 64; y++){
- for (uint8_t x = 0; x < 8; x++){
- LCD_gotoYX(y, x);
- LCD_word(y & 1 ? 0xF0F0 : 0x0F0F);
- }
- }
- delay(1000);
- for (uint8_t y = 0; y < 64; y++){
- for (uint8_t x = 0; x < 8; x++){
- LCD_gotoYX(y, x);
- LCD_word(y & 1 ? 0x0F0F : 0xF0F0);
- }
- }
- delay(1000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement