//PMC150 可用于苹果数据线,豆浆机,数码产品加密,汽车摩托车遥控器,定时器等多种小产品上。应广PMC150, 使用MINI-C开发,使用方便编译效率高,产品性能稳定,欢迎选用。
//让大家看看应广的MINI-C程序架构。附上项目文件夹,可直接用IDE打开旧专案进行编译调试,欢迎多交流。//PMC150 引脚定义
//================================================================================
// VDD |1 8| GND
// PA7 |2 7| PA0
// PA6 |3 6| PA4
// PA5/PRST# |4 5| PA3
//================================================================================
#include "extern.h"
.ramadr 0 //地址定义为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;
D_KEYPORT equ 0b_0000_0001
D_KEY1 equ 0b_0000_0001
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;
//pa3 电平翻转
a = pa;
a ^= 0x08;
pa = a;
}
}
//================================================================================
//TABLE
//--------------------------------------------------------------------------------
void Pr0_Skip(void)
{
pcadd a; //a = 1~n,a值等于0时不能跳出pcadd循环
{
ret 0xaa;
ret 0xbb;
ret 0xcc;
ret 0xdd;
ret 0xee;
}
}
//================================================================================
void FPPA0(void)
{
.ADJUST_IC SYSCLK=IHRC/4, IHRC=16MHz, VDD=5V;
pac = 0b_1111_1110; //pa0 pull high
pa = 0b_0000_0000;
paph = 0b_0000_0001;
$ padier 0b_1111_1001;
//------------------------------------------------------------
//清除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;
//------------------------------------------------------------
//从ROM中取数据
a = 0x02;
Pr0_Skip();
//------------------------------------------------------------
while (1)
{
.wdreset;
Test_DirectScanKey();
Test_KeyProcess();
}
}
//================================================================================
void Interrupt(void)
{
pushaf;
if(intrq.t16) //1MS
{
intrq.t16 = 0;
stt16 gw_T16Cnt;
//test IO
a = pa;
a ^= 0x80;
pa = a;
b_T16_1ms = 1;
gw_Cnt++;
if(gw_Cnt > 999)
{//1S计数
gw_Cnt = 0;
b_1S_F = 1;
}
}
popaf;
}
//================================================================================
PMC150.rar [迅雷下载] |