玩一玩几毛钱的PADAUK应广单片机跃龙PFC161。缥缈九哥借鉴网上代码测试。
包含一个1MS定时器与1个PA6输入按键反转PA4输出,以及PA5的2MS脉冲波,PA3的1秒反转信号。详细见代码:
#include "extern.h"
//================================================================================
.ramadr 0
word gw_Point;
.ramadr system
word gw_T16Cnt;
word gw_Cnt;
byte gb_Flag;
bit b_T16_1ms : gb_Flag.0 //1MS
bit b_1S_F : gb_Flag.1 //1S
byte gb_KeyDebounce;
byte gb_KeyNew;
byte gb_KeyOld;
byte gb_KeyValue;
//------------------------------------------------------------
//LED equ PA.3 // 设置PA3为LED输出
//PON equ PA.4 // 设置PA4为电源控制
//PWM equ PA.5 // 设置PA5为PWM输出
//KEY equ PA.6 // 设置PA6为按钮控制
D_KEYPORT equ 0b_0100_0000 // PA6 按键
D_KEY1 equ 0b_0100_0000 // PA6 按键
D_KeyBounce equ 30*1000/1024 // 30ms
//================================================================================
void Test_DirectScanKey(void)
{
if(b_T16_1ms)
{
b_T16_1ms = 0;
a = pa & D_KEYPORT;
a ^= D_KEYPORT;
if(gb_KeyNew == a)
{//读到值相同值,Debouce
if(--gb_KeyDebounce == 0)
{//Debounce结束
if(gb_KeyOld != gb_KeyNew)
{
gb_KeyValue = gb_KeyNew;
gb_KeyOld = gb_KeyNew;
}
}
}
else
{
gb_KeyNew = a;
gb_KeyDebounce = D_KeyBounce;
}
}
}
//================================================================================
void Test_KeyProcess(void)
{
//处理Key1
if(gb_KeyValue == D_KEY1)
{
gb_KeyValue = 0;
//pa4 电平翻转
a = pa;a ^= 0x10;pa = a;
}
}
//================================================================================
void FPPA0(void)
{
.ADJUST_IC SYSCLK=IHRC/4, IHRC=16MHz, VDD=5V;
clkmd.En_WatchDog = 1; // WatchDog Enable
// Insert Initial Code
//注:无PA.1,PA.2脚位
//未使用端口需有防漏电设置,如加内部上拉
PAPH = 0b0100_0000; //上拉控制寄存器,控制上拉高相应的引脚(1:启用,0:停用
PAPL = 0b0000_0000; //下拉控制寄存器,控制下拉高相应的引脚(1:启用,0:停用)
PAC = 0b1011_1001; //数据控制寄存器(1:输出模式,0:输入模式)
PA = 0b0000_0000; //数据寄存器
.delay 4000;
//------------------------------------------------------------
//清除RAM
gw_Point = _SYS(RAM_SIZE) - 1;
a = 0;
do
{
*gw_Point = a;
} while (--gw_Point$0);
//------------------------------------------------------------
//初始化定时器 定时1MS
gw_Point = 1024 - 1000;
stt16 gw_T16Cnt;
$ t16m SYSCLK,/4,bit10;
intrq = 0;
inten.2 = 1;
engint;
//------------------------------------------------------------
while (1)
{
// ...
if(b_1S_F)
{
b_1S_F = 0;
//PA3 反转
a = pa; a ^= 0x08;pa = a;
}
Test_DirectScanKey();
Test_KeyProcess();
.wdreset;
}
}
//================================================================================
void Interrupt (void)
{
pushaf;
if (Intrq.T16)
{ // T16 Trig
// User can add code
Intrq.T16 = 0;
//...
stt16 gw_T16Cnt;
//pa5 电平翻转
a = pa;a ^= 0x20;pa = a;
b_T16_1ms = 1;
gw_Cnt++;
if(gw_Cnt > 999)
{//1S计数
gw_Cnt = 0;
b_1S_F = 1;
}
}
popaf;
}
//缥缈九哥测试完毕!
//================================================================================
源码包:9G-LED.rar
离线
不知道放什么板块。只好放到RISC-V里了。
离线