-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add new project control newpixels
- Loading branch information
1 parent
1f9cf7a
commit 3b8868c
Showing
11 changed files
with
2,095 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
# =================================================================================== | ||
# Project: Examples for CH55x | ||
# Author: CésarBautista | ||
# Year: 2023 | ||
# =================================================================================== | ||
# Type "make help" in the command line. | ||
# =================================================================================== | ||
# File Names | ||
SKETCH = main.c | ||
TARGET = $(basename $(SKETCH)) | ||
INCLUDE = src | ||
|
||
# Microcontroller Settings | ||
FREQ_SYS = 16000000 | ||
XRAM_LOC = 0x0100 | ||
XRAM_SIZE = 0x0300 | ||
CODE_SIZE = 0x3800 | ||
|
||
# Toolchain | ||
CC = sdcc | ||
OBJCOPY = objcopy | ||
PACK_HEX = packihx | ||
|
||
# if linux use python3, if windows use python | ||
WCHISP ?= python prog/uploader.py | ||
|
||
# Compiler Flags | ||
CFLAGS = -mmcs51 --model-small --no-xinit-opt | ||
CFLAGS += --xram-size $(XRAM_SIZE) --xram-loc $(XRAM_LOC) --code-size $(CODE_SIZE) | ||
CFLAGS += -I$(INCLUDE) -DF_CPU=$(FREQ_SYS) | ||
CFILES = $(SKETCH) $(wildcard $(INCLUDE)/*.c) | ||
RFILES = $(CFILES:.c=.rel) | ||
CLEAN = rm -f *.ihx *.lk *.map *.mem *.lst *.rel *.rst *.sym *.asm *.adb | ||
|
||
# Symbolic Targets | ||
help: | ||
@echo "Use the following commands:" | ||
@echo "make all compile, build, and keep all files" | ||
@echo "make hex compile and build $(TARGET).hex" | ||
@echo "make bin compile and build $(TARGET).bin" | ||
@echo "make flash compile, build, and upload $(TARGET).bin to the device" | ||
@echo "make clean remove all build files" | ||
|
||
%.rel : %.c | ||
@echo "Compiling $< ..." | ||
@$(CC) -c $(CFLAGS) $< | ||
|
||
$(TARGET).ihx: $(RFILES) | ||
@echo "Building $(TARGET).ihx ..." | ||
@$(CC) $(notdir $(RFILES)) $(CFLAGS) -o $(TARGET).ihx | ||
|
||
$(TARGET).hex: $(TARGET).ihx | ||
@echo "Building $(TARGET).hex ..." | ||
@$(PACK_HEX) $(TARGET).ihx > $(TARGET).hex | ||
|
||
$(TARGET).bin: $(TARGET).ihx | ||
@echo "Building $(TARGET).bin ..." | ||
@$(OBJCOPY) -I ihex -O binary $(TARGET).ihx $(TARGET).bin | ||
|
||
flash: $(TARGET).bin size removetemp | ||
@echo "Uploading to CH55x ..." | ||
@$(WCHISP) $(TARGET).bin | ||
|
||
all: $(TARGET).bin $(TARGET).hex size | ||
|
||
hex: $(TARGET).hex size removetemp | ||
|
||
bin: $(TARGET).bin size removetemp | ||
|
||
bin-hex: $(TARGET).bin $(TARGET).hex size removetemp | ||
|
||
install: flash | ||
|
||
size: | ||
@echo "------------------" | ||
@echo "FLASH: $(shell awk '$$1 == "ROM/EPROM/FLASH" {print $$4}' $(TARGET).mem) bytes" | ||
@echo "IRAM: $(shell awk '$$1 == "Stack" {print 248-$$10}' $(TARGET).mem) bytes" | ||
@echo "XRAM: $(shell awk '$$1 == "EXTERNAL" {print $(XRAM_LOC)+$$5}' $(TARGET).mem) bytes" | ||
@echo "------------------" | ||
|
||
removetemp: | ||
@echo "Removing temporary files ..." | ||
@$(CLEAN) | ||
|
||
clean: removetemp | ||
@echo "Cleaning all up ..." | ||
@$(CLEAN) | ||
@rm -f $(TARGET).hex $(TARGET).bin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
// =================================================================================== | ||
// Libraries, Definitions and Macros | ||
// =================================================================================== | ||
// Code Rewrite by Master | ||
// ------- CH552 | ||
// +--\/--+ | ||
// ---------------- P32 1|° |16 V33 ------------- | ||
// ---------------- P14 2| |15 Vcc ------------- | ||
// ---------------- P15 3| |14 GND ------------- | ||
// ---------------- P16 4| |13 P37 UDM --- USB D- | ||
// ---------------- P17 5| |12 P36 UDP --- USB D+ | ||
// ---------------- RST 6| |11 P34 ------------- | ||
// ---------------- P31 7| |10 P33 ---------DOUT | ||
// ---------------- P30 8| |9 P11 ------------- | ||
// +------+ | ||
|
||
// Libraries | ||
|
||
|
||
#include "src/system.h" // system functions | ||
#include "src/delay.h" // delay functions | ||
#include "src/neo.h" // NeoPixel functions | ||
#include <stdlib.h> // for random number generation | ||
|
||
// =================================================================================== | ||
// NeoPixel Functions | ||
// =================================================================================== | ||
|
||
// Pin definitions | ||
#define PIN_NEO P33 // pin connected to NeoPixel | ||
// | ||
|
||
|
||
|
||
#define delay 100 | ||
#define NeoPixel 16 // Number Neopixel conect | ||
#define level 100 // Ilumination level 0 to 255 | ||
|
||
void randomColorSequence(void) { | ||
|
||
for(int j=0;j<NeoPixel;j++){ | ||
uint8_t red = rand() % level; | ||
uint8_t green = rand() % level; | ||
uint8_t blue = rand() % level; | ||
uint8_t num = rand() % NeoPixel; | ||
|
||
for(int i=0; i<num; i++){ | ||
NEO_writeColor(0, 0, 0); | ||
} | ||
NEO_writeColor(red, green, blue); | ||
DLY_ms(delay); | ||
NEO_writeColor(0, 0, 0); | ||
} | ||
|
||
for(int l=0; l<9; l++){ | ||
NEO_writeColor(0, 0, 0); | ||
} | ||
|
||
} | ||
|
||
void colorSequence(void) { | ||
|
||
for(int j=0;j<=NeoPixel;j++){ | ||
uint8_t red = rand() % level; | ||
uint8_t green = rand() % level; | ||
uint8_t blue = rand() % level; | ||
for(int i=0; i<j; i++){ | ||
NEO_writeColor(red, green, blue); | ||
} | ||
DLY_ms(delay); | ||
for(int l=0; l<j; l++){ | ||
NEO_writeColor(0, 0, 0); | ||
} | ||
} | ||
} | ||
|
||
// =================================================================================== | ||
// Main Function | ||
// =================================================================================== | ||
void main(void) { | ||
NEO_init(); // init NeoPixels | ||
CLK_config(); // configure system clock | ||
DLY_ms(delay); // wait for clock to settle | ||
|
||
// Loop | ||
while (1) { | ||
randomColorSequence(); | ||
DLY_ms(100); | ||
colorSequence(); | ||
DLY_ms(100); | ||
} | ||
} |
Oops, something went wrong.