Skip to content

Instantly share code, notes, and snippets.

@ksasao
Last active May 1, 2025 01:18
Show Gist options
  • Save ksasao/b14b6a2edd86cecea52346dbdf2751ab to your computer and use it in GitHub Desktop.
Save ksasao/b14b6a2edd86cecea52346dbdf2751ab to your computer and use it in GitHub Desktop.
8pin RISC-V マイコン CH32V003J4M6 で NeoPixel Lチカ https://x.com/ksasao/status/1917595665515045326
// 8pin RISC-V マイコン CH32V003J4M6 で NeoPixel Lチカ
// https://x.com/ksasao/status/1917595665515045326
// ■ パーツ
// CH32V003J4M6 https://akizukidenshi.com/catalog/g/g118062/
// マイコン内蔵RGBLEDモジュール https://akizukidenshi.com/catalog/g/g108414/
//
// コードはほぼ下記を参照しています
// amanoya3: ArduinoでRISC-VマイコンCH32V003にNeoPixelのLEDをつないでみた
// https://ameblo.jp/pta55/entry-12813320408.html
// I/O Pin: PD6(PORTD, bit 6) - 1番ピン
#define D_STB *(unsigned long *)0x40011410
#define lednumber_max 1
byte aData[lednumber_max][3];
byte lednumber = lednumber_max;
void allset(byte r, byte g, byte b){
for(byte i=0; i<lednumber_max;i++){
aData[i][0]=g;
aData[i][1]=r;
aData[i][2]=b;
}
}
void sendData(){
noInterrupts();
volatile unsigned long d6Current = D_STB | 0x0040;
for(byte numLed=0; numLed<lednumber; numLed++){
for(byte rgbLed=0; rgbLed < 3;rgbLed++){
byte a=aData[numLed][rgbLed];
for(byte i=0;i<8;i++){
byte hl=a & 0x80;
if(hl>0){ // H: 600ns, L: 500ns
D_STB = d6Current; // High - 100ns
digitalWriteFast(PD_6, HIGH); // High - 500ns
digitalWriteFast(PD_6, LOW); // Low - 500ns
}else{ // H: 200ns, L: 500ns
D_STB |= d6Current; // High - 200ns
digitalWriteFast(PD_6, LOW); // Low - 500ns
}
a=a*2;
}
}
}
interrupts();
}
void setup(){
pinMode(PD6, OUTPUT);
byte r,g,b;
r=0;g=0;b=0; allset(r,g,b);sendData(); delay(500);
}
void loop(){
byte r,g,b;
r=64;g=0;b=0; allset(r,g,b);sendData(); delay(500);
r=0;g=64;b=0; allset(r,g,b);sendData(); delay(500);
r=0;g=0;b=64; allset(r,g,b);sendData(); delay(500);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment