赞
踩
目录
应广科技网址,开发工具,PMS123规格书:http://www.padauk.com.tw/cn/product/show.aspx?num=145&kw=PFS123
- #include "extern.h"
- COM1 equ pc.3
- COM2 equ pa.7
- COM3 equ pa.6
- jia equ pb.4
- jian equ pb.6
- byte m;
- byte num_bit;
- byte num_ten;
- word reload_T16;
- bit j;
- word counter=0;
-
- void Look_Table(void)
- {
- A += 1;
- _Pcadd
- {
- ret 0x3f;//0
- ret 0x06;//1
- ret 0x5b;//2
- ret 0x4f;//3
- ret 0x66;//4
- ret 0x6d;//5
- ret 0x7d;//6
- ret 0x07;//7
- ret 0x7f;//8
- ret 0x6f;//9
- }
- }
-
- void T16_Time(void)
- {
- $ T16M SYSCLK,/4,bit12; //T16的时钟源选择,内部的时钟分频器,中断源选择(当选择位由低到高或者由高到低时,发生中断事件);
- //时钟源选择可以选择STOP, SYSCLK, PA4_F, IHRC, EOSC, ILRC, PA0_F;分频器可选择/1, /4, /16, /64
- //中断源可选择BIT8, BIT9, BIT10, BIT11, BIT12, BIT13, BIT14, BIT15
- reload_T16 = 4096-500; //每次进中断为1ms;
- //计算公式为 [1/(时钟源/分频器)]*(中断源-reload_T16)=[1/(4M/4)]*(2^12-(4096-1000))=1000us=1ms
-
- stt16 reload_T16; //设定计数器初始值reload_T16,当计数器累加超过设定中断源时产生中断;
-
- $ INTEN T16; //中断允许寄存器,启用从T16的溢出中断;1:启用,0:停用。
- $ INTRQ T16; //中断请求寄存器,此位是由硬件置位并由软件清零;1:请求,0:不请求。
- //注:INTEN,INTRQ没有初始值,所以要使用中断前,一定要根据需要设定数据。即使INTEN为0,INTRQ还是会被中断发生源触发。
- $ INTEGS BIT_R; //T16中断边缘选择,上升缘请求中断为BIT_R,下降缘请求中断为BIT_F;默认为上升缘请求。
- INTEN.T16 = 1; //开T16中断
- INTRQ.T16 = 0; //清零INTRQ寄存器。
- ENGINT; //打开全局中断
- }
-
- void xianshi(void)
- {
-
- A = num_ten;
- Look_Table();
- m = A;
- PA = m & 0x01; //a-> pa0=1,其他的关
- PB = m & 0x00;
- PC = m & 0x00;
- $ COM1 out,low; //c3为共阴极=0,a->f流水灯
- $ COM2 out,high;
- $ COM3 out,high;
- .delay 1000;
-
- PA = (m<<3) & 0x10; //b-> a4=1,其他的关
- PB = m & 0x00;
- PC = m & 0x00;
- $ COM1 out,low; //c3为共阴极=0,a->f流水灯
- $ COM2 out,high;
- $ COM3 out,high;
- .delay 1000;
-
- PA = (m<<1 )& 0x08; //c a3=1,其他的关
- PB = m & 0x00;
- PC = m & 0x00;
- $ COM1 out,low; //c3为共阴极=0,a->f流水灯
- $ COM2 out,high;
- $ COM3 out,high;
- .delay 1000;
-
- PA = m & 0x00; //d c0=1,其他的关
- PB = m & 0x00;
- PC = (m>>3) & 0x01;
- $ COM1 out,low; //c3为共阴极=0,a->f流水灯
- $ COM2 out,high;
- $ COM3 out,high;
- .delay 1000;
-
- PA = m & 0x00; //e c1=1,其他的关
- PB = m & 0x00;
- PC = (m>>3) & 0x02;
- $ COM1 out,low; //c3为共阴极=0,a->f流水灯
- $ COM2 out,high;
- $ COM3 out,high;
- .delay 1000;
-
- PA = m & 0x00; //f b0=1,其他的关
- PB = (m>>5) & 0x01;
- PC = m & 0x00;
- $ COM1 out,low; //c3为共阴极=0,a->f流水灯
- $ COM2 out,high;
- $ COM3 out,high;
- .delay 1000;
-
- PA = (m>>2) & 0x10; //g a6=0,a4=1,其他的关
- PB = m & 0x00;
- PC = m & 0x00;
- $ COM1 out,high;
- $ COM2 out,high;
- $ COM3 out,low; //a6为共阴极=0,开g数码管
- .delay 1000;
-
- /*个位分两部分*/
- A = num_bit;
- Look_Table();
- m = A;
- PA = m & 0x01; //a-> pa0=1,其他的关
- PB = m & 0x00;
- PC = m & 0x00;
- $ COM1 out,high; //c3为共阴极=0,a->f流水灯
- $ COM2 out,low;
- $ COM3 out,high;
- .delay 1000;
-
- PA = (m<<3) & 0x10; //b-> a4=1,其他的关
- PB = m & 0x00;
- PC = m & 0x00;
- $ COM1 out,high; //c3为共阴极=0,a->f流水灯
- $ COM2 out,low;
- $ COM3 out,high;
- .delay 1000;
-
- PA = (m<<1 )& 0x08; //c a3=1,其他的关
- PB = m & 0x00;
- PC = m & 0x00;
- $ COM1 out,high; //c3为共阴极=0,a->f流水灯
- $ COM2 out,low;
- $ COM3 out,high;
- .delay 1000;
-
- PA = m & 0x00; //d c0=1,其他的关
- PB = m & 0x00;
- PC = (m>>3) & 0x01;
- $ COM1 out,high; //c3为共阴极=0,a->f流水灯
- $ COM2 out,low;
- $ COM3 out,high;
- .delay 1000;
-
- PA = m & 0x00; //e c1=1,其他的关
- PB = m & 0x00;
- PC = (m>>3) & 0x02;
- $ COM1 out,high; //c3为共阴极=0,a->f流水灯
- $ COM2 out,low;
- $ COM3 out,high;
- .delay 1000;
-
- PA = m & 0x00; //f b0=1,其他的关
- PB = (m>>5) & 0x01;
- PC = m & 0x00;
- $ COM1 out,high; //c3为共阴极=0,a->f流水灯
- $ COM2 out,low;
- $ COM3 out,high;
- .delay 1000;
-
- PA = (m>>3) & 0x08; //g a6=0,a3=1,其他的关
- PB = m & 0x00;
- PC = m & 0x00;
- $ COM1 out,high;
- $ COM2 out,high;
- $ COM3 out,low; //a6为共阴极=0,开g数码管
- .delay 1000;
- }
-
- void anjian(void)
- {
- if(j)//1ms 中断扫描
- {
- j=0;
- if(jia==0)
- {
- if(jia==0)
- {
- if(counter<1500) counter++;//jishi
- if(counter==20)//长按
- {
- if(num_bit<10) {num_bit++;}
- if(num_bit==10) {num_bit=0;num_ten++;if(num_ten>=10)num_ten=0;}
- counter=0;
- }
-
- }
- else
- {
- if(counter>4&&counter<20)//xiaodou duanan
- {
- if(num_bit<10) {num_bit++;}
- if(num_bit==10) {num_bit=0;num_ten++;if(num_ten>=10)num_ten=0;}
-
- }
- counter=0;
- }
- }
- if(jian==0)
- {
- if(jian==0)
- {
- if(counter<1500) counter++;//jishi
- if(counter==20)//长按
- {
-
- if((num_bit>0||num_bit==0 )&& num_ten==0)
- {
- if(!num_bit)
- {
- num_bit=9;num_ten=9;
-
- }
- else
- {
- num_bit--;
- }
- }
-
- else if(num_ten>0 && (num_bit>0||num_bit==0 ))
- {
- if(!num_bit)
- {
- num_ten--;
- num_bit=9;
- }
- else
- {
- num_bit--;
- }
-
- }
- counter =0;
- }
-
- }
- else
- {
- if(counter>4&&counter<20)//xiaodou duanan
- {
-
- if((num_bit>0||num_bit==0 )&& num_ten==0)
- {
- if(!num_bit)
- {
- num_bit=9;num_ten=9;
-
- }
- else
- {
- num_bit--;
- }
- }
-
- else if(num_ten>0 && (num_bit>0||num_bit==0 ))
- {
- if(!num_bit)
- {
- num_ten--;
- num_bit=9;
- }
- else
- {
- num_bit--;
- }
-
- }
- }
- counter=0;
- }
- }
- }
-
- }
-
- void FPPA0 (void)
- {
- .ADJUST_IC SYSCLK=IHRC/8, IHRC=16MHz, VDD=5V;
- num_ten = 2;
- num_bit = 5;
- PAC = 0b1101_1001;
- PBC = 0b0000_0001;
- PCC = 0B0000_1011;
- PA = 0b0000_0000;
- PB = 0b0000_0000;
- PC = 0b0000_0000;
- $ jia in,pull; //输入上拉
- $ jian in,pull; //输入上拉
- T16_Time();
- .delay 10000;
-
- while (1)
- {
- xianshi();
- anjian();
- }
-
- }
-
- void Interrupt (void)
- {
- pushaf; //进栈
- if (Intrq.T16)
- {
- Intrq.T16=0;
- stt16 reload_T16;
- j=1;
- }
- popaf; //出栈
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。