マイコンSTC12C5204ADの使い方1
使用機材
aitendo_
8051コアマイコン [STC12C5204AD-35I-SKDIP28]
aitendo_USB-UART変換 [U2UART2102-6PMCU]
aitendo_抵抗内蔵角形LED [LED234R-WC5V]
ブレッドボード
回路
マイコンPORT/
3/--10K--GND
4/--USB-UART変換TXO
5/--USB-UART変換RXI
11(P3_5)/--LED--GND
14/--GND
28/--SW--+5V
USB-UART変換をパソコンに認識させます。
aaa@aaa:~$ lsusb
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 008 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 007 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 006 Device 004: ID 10c4:ea60 Cygnal Integrated Products, Inc. CP210x UART Bridge / myAVR
mySmartUSB light
Device004が変換器で、ID=10c4:ea60を控えます。
cd /etc/udev/rules.d/
sudo leafpad 54-udev.rules
ファイルに
KERNEL=="ttyUSB*", ATTRS{idVendor}=="10c4", ATTRS{idProduct}=="ea60", GROUP="uucp", MODE="0666"
と入力して保存します。
配線をチェックします。
aaa@aaa:~$ stcgal
Waiting for MCU, please cycle power: done
Protocol detected: stc12b
Target model:
Name: STC12C5204AD
Magic: E164
Code flash: 4.0 KB
EEPROM flash: 2.0 KB
Target frequency: 10.944 MHz
Target BSL version: 6.6H
Target options:
reset_pin_enabled=True
low_voltage_reset=False
oscillator_stable_delay=32768
por_reset_delay=short
clock_gain=high
clock_source=externa
watchdog_por_enabled=False
watchdog_stop_idle=True
watchdog_prescale=256
eeprom_erase_enabled=False
bsl_pindetect_enabled=False
Disconnected!
aaa@aaa:~$
-----------------------------
#include <8052.h>
void delay(void);
void main(void)
{
while(1)
{
P3_5 = 0xFF; // Turn ON all LED's connected to Port1
delay();
P3_5 = 0x00; // Turn OFF all LED's connected to Port1
delay();
}
}
void delay(void)
{
int i,j;
for(i=0;i<0xff;i++)
for(j=0;j<0xff;j++);
}
-------------------------------------
上記プログラムをled1.cとします。
sdccでコンパイルします。
aaa@aaa:~/Desktop/8051コア/STC12C5204AD/op1$ ls
led1.c op1
aaa@aaa:~/Desktop/8051コア/STC12C5204AD/op1$ sdcc led1.c
aaa@aaa:~/Desktop/8051コア/STC12C5204AD/op1$ ls
led1.asm led1.ihx led1.lst led1.mem led1.rst op1
led1.c led1.lnk led1.map led1.rel led1.sym
aaa@aaa:~/Desktop/8051コア/STC12C5204AD/op1$ stcgal led1.ihx
Waiting for MCU, please cycle power: done
Protocol detected: stc12b
Target model:
Name: STC12C5204AD
Magic: E164
Code flash: 4.0 KB
EEPROM flash: 2.0 KB
Target frequency: 10.973 MHz
Target BSL version: 6.6H
Target options:
reset_pin_enabled=True
low_voltage_reset=False
oscillator_stable_delay=32768
por_reset_delay=short
clock_gain=high
clock_source=external
watchdog_por_enabled=False
watchdog_stop_idle=True
watchdog_prescale=256
eeprom_erase_enabled=False
bsl_pindetect_enabled=False
Loading flash: 152 bytes (Intel HEX)
Switching to 19200 baud: testing setting done
Erasing 2 blocks: done
Writing flash: 640 Bytes [00:00, 2309.99 Bytes/s]
Finishing write: done
Setting options: Protocol error: incorrect magic in option packet
Disconnected!
aaa@aaa:~/Desktop/8051コア/STC12C5204AD/op1$
下記写真に結果を示します。