gcht101hello/code20240501.htm6 20240506
Sorce Code:MKAC122i2clcd20240506
hello

    MKAC122l2clcd20240506
description: show on lcd2004  0x27
board: MILK-V duo 256MB on soldered universal board
SOC: SG2002 RISC-V C906@1Ghz + C906@700MHz
SD CARD:arduino-milkv-duo-v1.0.9-2024-0228.img.zip
USB RNDIS >> ssh root@192.168.42.1 >> password: milkv
Linux milkv-duo 5.10.4-tag- #1 PREEMPT Wed Feb 28 14:26:31 CST 2024 riscv64 GNU/Linux
cat /etc/os-release >> NAME=Buildroot  VERSION=20240228-1428
device: i2clcd2004, USB-TTL 
language : C/C++
IDE: Arduino IDE: 2.3.2 and VS code on wsl windows11
Tools >> board Duo256 Dev module,COM12(Duo256)
Programmer : Burntool
Serial monitor: Vs code 115200baud
https://milkv.io/docs/duo/getting-started/arduino
pinout
      1  1 GP0      VBUS 40  
      2  2 GP1      VSYS 39
GND      3 GND      GND  38 
    PWM7 4 GP2      3V3EN37
    PWM6 5 GP3      3V3OUT36
USBTTLRX 6 GP4/TX3   35
USBTTLTX 7 GP5/RX3   34
         8 GND      GND  33     
         9 GP6      GP27 32
         10 GP7     GP26 31 ADC1
SDA      11 GP8/SDA1 RUN 30
SCL      12 GP9/SCL1 GP22 29 
GND      13 GND      GND  28
    14   14 GP10/SDA2 GP21 27 27
    15   15 GP11/SCL2 GP20 26 26
         16 GP12      GP19 25 25
         17 GP13      GP18 24 24
GND      18 GND       GND  23 
    19   19 GP14      GP17 22 22
LED 20   20 GP15      GP16 21 21 
connection:SDA/PIN11:SDA lcd2004  
connection:SCL/PIN12:SCL lcd2004
connection:TX3/PIN6:USBTTL/RX
connection:RX3/PIN7:USBTTL/TX   
*/

//
#include "I2C_LCD.h"
#define BACKLIGHT_PIN   3 //i2clcd 20x4 
#define En_pin          2
#define Rw_pin          1
#define Rs_pin          0
#define D4_pin          4
#define D5_pin          5
#define D6_pin          6
#define D7_pin          7
I2C_LCD lcd(0x27);
struct Codeinfo{
  char codeId[9];
  char function[9];
  char board[16];
  char mpu[9];
  byte version;
  long date; 
};
struct Interval{
  byte count;
  long previous;
  long interval;
};
struct Codeinfo ci={"MKAC122","i2clcd","MILKV duo25b","SG2002",1,20240506};
struct Interval in={0,0,1};
void ciShow(void);
//-------------------------------------------------
void setup(){
  pinMode(20,OUTPUT);
  Serial.begin(115200);
  while (!Serial);
  Serial.println(__FILE__);
  Serial.print("I2C_LCD_LIB_VERSION: ");
  Serial.println(I2C_LCD_LIB_VERSION);
  ciShow();

  lcd.config(39, En_pin, Rw_pin, Rs_pin, D4_pin, D5_pin, D6_pin, D7_pin, BACKLIGHT_PIN, POSITIVE);
  Wire.begin();
  Wire.print();
  Wire.setClock(100000);
  lcd.begin(20, 4);
  lcd.display();
  delay(1000);
  lcd.noDisplay();
  delay(1000);
  lcd.display();
  lcd.clear();

  lcd.home();
  lcd.setCursor(5, 1);
  uint32_t start = micros();
  lcd.print(__TIME__);
  uint32_t stop = micros();
  lcd.setCursor(14, 1);
  lcd.print(stop - start); 
  delay(1000);
  lcd.setCursor(0, 3);
  lcd.print("MILK-V duo 256MB");
  delay(2000);
}
//-------------------------------------------------
void loop(){
  if (millis()-in.previous>in.interval*1000){
    in.previous=millis();
    lcd.home();
    lcd.print("mSec:");
    lcd.setCursor(5, 0);
    lcd.print(millis());

    lcd.setCursor(5, 1);
    lcd.print(__TIME__);
    digitalWrite(20,!digitalRead(20));
    Serial.printf("{\"millis\":%ld}\r\n",millis());
  delay(1000);
  }
}
//-------------------------------------------------------
void ciShow(void){
  Serial.printf("codeId:%s%s \r\n",ci.codeId,ci.function);
  Serial.printf("%s %s\r\n",ci.board,ci.mpu);
  Serial.printf("date:%d\r\n",ci.date);
} 


/*  result
13:47:00:744 -> I2C_LCD_LIB_VERSION: 0.2.1
13:47:00:746 -> codeId:MKAC122i2clcd 
13:47:00:747 -> MILKV duo25b SG2002
13:47:00:750 -> date:20240506
13:47:00:750 -> Wire1: 0
13:47:00:751 -> [iic_dump_register]: ===dump start
13:47:00:754 -> IC_CON = 0x65
13:47:00:755 -> IC_TAR = 0x27
13:47:00:758 -> IC_SAR = 0
13:47:00:758 -> IC_SS_SCL_HCNT = 0x1ab
13:47:00:761 -> IC_SS_SCL_LCNT = 0x1f3
13:47:00:762 -> IC_ENABLE = 0
13:47:00:763 -> IC_STATUS = 0x6
13:47:00:766 -> IC_INTR_MASK = 0
13:47:00:766 -> IC_INTR_STAT = 0
13:47:00:768 -> IC_RAW_INTR_STAT = 0
13:47:00:770 -> [iic_dump_register]: ===dump end
13:47:55:341 -> {"millis":54603}
13:47:56:352 -> {"millis":55614}
13:47:57:363 -> {"millis":56625}
*/