| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 611 人关注过本帖
标题:[求助]各位好!请帮助解释一下此程序,谢谢!
只看楼主 加入收藏
wtj876
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2007-7-29
收藏
 问题点数:0 回复次数:3 
[求助]各位好!请帮助解释一下此程序,谢谢!

#include <pic.h>

#define PORTAIT(adr,bitn) ((unsigned)(&adr)*8+(bitn))
static bit LED_CONT @ PORTAIT(PORTD,5);
static bit K1 @ PORTAIT(PORTC,0);
static bit K2 @ PORTAIT(PORTC,1);
static bit K3 @ PORTAIT(PORTC,2);
static bit K4 @ PORTAIT(PORTC,3);
static bit K5 @ PORTAIT(PORTC,4);
static bit K6 @ PORTAIT(PORTC,6);

static bit MUTE_L @ PORTAIT(PORTB,7); //40p
static bit FLAG_L @ PORTAIT(PORTB,1); //34p
static bit MUTE_R @ PORTAIT(PORTB,6); //39p
static bit FLAG_R @ PORTAIT(PORTC,7); //26p
static bit MUTE_ALL @ PORTAIT(PORTC,6); //25p

#define SET 0x03
#define LEFT 0x04
#define RIGHT 0x05
#define POWER_F 0x06
#define POWER_S 0x16
#define DISP_KEY 0x08
#define LOCK_KEY 0x09
#define FREQ_KEY 0x0a

bit mute_A,mute_B;
bit low_batt_A,low_batt_B;
bit rf_A,rf_B;
bit power_on;

bank1 unsigned char save_en;
bank1 unsigned char adc_result[4];//0--RF_L;1--RF_R;2--AF_R;3--AF_L
bank1 unsigned char lock[2],fq_ch[2],fq[2],part_s;
bank1 unsigned char key,bianma,now_key;
bank1 unsigned char out1_str,out1_enable,out2_str,out2_enable;
bank1 unsigned char type_a,type_b;
bank1 unsigned char xunhuan,delay_time;
bank1 unsigned char set_n;
bank1 unsigned char power_time;

extern void init_PLL(void);
extern void setup_freq(void);
extern void cont_LCM(unsigned char pt,unsigned char on_off);
extern void init_LCM(void);
extern void display_pro(void);

extern unsigned char rd24c01(unsigned char addr);

extern void save_data(void);
extern void read_data(void);

void delay(unsigned char t)
{
while(t--);
}
void read_key(void)
{
static unsigned char old_key63=0,key_time=0;
unsigned char key63=0;
if(K1==0)key63=1;
if(K2==0)key63=2;
if(K3==0)key63=3;
if(K4==0)key63=4;
if(K5==0)key63=5;
if(K6==1)key63=6;
if(key63==old_key63){
if(key_time){
key_time--;
key63=0;
}
else {
key_time=2;
if(key63)key63+=0x10;
}
}
else {
old_key63=key63;
key_time=6;
}
if(key63==0x01||key63==0x11)bianma=1;
else if(key63==0x02||key63==0x12)bianma=2;
else key=key63;
}
void part_select(unsigned char p)
{
part_s=p;
save_en=0;
out2_str=fq_ch[part_s-1];
now_key=FREQ_KEY;
out2_enable=1;
}
void fr_ch_disp(unsigned char as)
{
if(part_s){
if(as)fq_ch[part_s-1]=as-1;//FREQ//CHANNAL
out2_str=fq_ch[part_s-1]+4;
out1_enable=0;
out2_enable=1;
save_en=1;
}
}
void freq_pro(unsigned char as)
{
unsigned char temp,temp_r;
if(part_s){
temp=part_s-1;
if(temp)temp_r=0;
else temp_r=1;
if(lock[temp]==0){
if(as==1){
repeat1: fq[temp]++;
if(fq[temp]==101)fq[temp]=0;
if(fq[temp]==fq[temp_r])goto repeat1;
}
if(as==2){
repeat2: if(fq[temp])fq[temp]--;
else fq[temp]=100;
if(fq[temp]==fq[temp_r])goto repeat2;
}
out2_str=fq_ch[temp];
out1_enable=0;
out2_enable=1;
save_en=1;
}
else {
out1_str=3; //lock on
out1_enable=1;
out2_str=fq_ch[part_s-1];
out2_enable=2;
save_en=2;
}
}
}
void lock_pro(unsigned char as)
{
if(part_s){
if(as)lock[part_s-1]=2-as;//LOCK ON/OFF
out2_str=lock[part_s-1]+6;
out1_enable=0;
out2_enable=1;
save_en=1;
}
}
void set_pro(void)
{
if(part_s){
if(save_en){
save_data();
save_en=0;
delay_time=1;
read_data();
setup_freq();
}
else {
set_n++;
if(set_n==3)set_n=0;
out1_str=set_n+1;
switch(set_n){
case 0: out1_str=out2_str=fq_ch[part_s-1]; now_key=FREQ_KEY;break; //FREQ
case 1: out2_str=fq_ch[part_s-1]+4;now_key=DISP_KEY;break; //DSPLAY
case 2: out2_str=lock[part_s-1]+6; now_key=LOCK_KEY;break; //LOCK
default:break;
}
out1_enable=1;
out2_enable=2;
}
}
}
void resest_pro(void)
{
set_n=0;
part_s=0;
save_en=0;
type_a=fq_ch[0];
type_b=fq_ch[1];
read_data();
cont_LCM(3,1);
display_pro();
now_key=FREQ_KEY;
}
void sys_display(void)
{
if(out1_enable){
if(part_s==1)type_a=out1_str;
else type_a=fq_ch[0];
if(part_s==2)type_b=out1_str;
else type_b=fq_ch[1];
display_pro();
out1_enable=0;
delay_time=45;
}
if(out2_enable==1||(delay_time==19&&out2_enable==2)){
if(part_s==1)type_a=out2_str;
else type_a=fq_ch[0];
if(part_s==2)type_b=out2_str;
else type_b=fq_ch[1];
display_pro();
out2_enable=0;
delay_time=20;
}
if(delay_time){
delay_time--;
if(delay_time==0)resest_pro();
}
}
void power_on_off()
{
unsigned int n;
if(power_on){
init_PLL();
resest_pro();
MUTE_ALL=0;
}
else {
out1_str=out2_str=8;
type_a=8;
type_b=8;
display_pro();
n=1200;
while(n--){
delay(255);
}
cont_LCM(3,0);
MUTE_ALL=1;
}
LED_CONT=power_on;
}
void power_pro(void)
{
if(power_time<9)power_time++;
if(power_time==8){
power_on=!power_on;
save_data();
power_on_off();
}
}
void key_pro(void)
{
if(key==POWER_S)power_pro();
else power_time=0;
if(power_on==1){
xunhuan=0;
switch(key){
case SET: set_pro();break;
case LEFT: part_select(1);break;
case RIGHT: part_select(2);break;
case FREQ_KEY: freq_pro(bianma);break;
case DISP_KEY: fr_ch_disp(bianma);break;
case LOCK_KEY: lock_pro(bianma);break;
default:break;
}
}
key=0;
bianma=0;
}
void op_san_pro(void)
{
static unsigned char san=0,old_part;
if(old_part!=part_s){
cont_LCM(3,1);
old_part=part_s;
set_n=0;
}
if(part_s){
san++;
if(san==3){
cont_LCM(part_s,1);
}
if(san==24){
san=0;
cont_LCM(part_s,0);
}
}
}
void adc_pro(void)
{
static unsigned char adc_ch=0,fenpin=0;
unsigned char temp,old_adc;
while(ADGO);
if(adc_ch<2){
if(ADRES>35)ADRES-=35;
else ADRES=0;
temp=ADRES>>3;
}
else {
temp=ADRES>>4;
if(adc_ch==2){
if(mute_B)temp=0;
}
if(adc_ch==3){
if(mute_A)temp=0;
}
}
if(temp>8)temp=8;
old_adc=adc_result[adc_ch];
if(adc_ch==0){
if((temp>(old_adc+2))||(old_adc>(temp+1)))rf_A=!rf_A;
}
if(adc_ch==1){
if((temp>(old_adc+2))||(old_adc>(temp+1)))rf_B=!rf_B;
}
adc_result[adc_ch]=temp;
adc_ch++;
if(adc_ch>3)adc_ch=0;
ADCON0=0x41|(adc_ch<<3);//start ADC
if(!adc_ch){
display_pro();
}
else delay(255);

ADGO=1;
}
void init_24c01(void)
{
power_on=0;
lock[0]=0;
lock[1]=0;
fq_ch[0]=0;
fq_ch[1]=0;
fq[0]=0;
fq[1]=1;
if(rd24c01(0)!=0xa5)save_data();
else read_data();
}
void main(void)
{
unsigned char kkn,ccn_A,ccn_B;
OPTION=0x0f;
TRISD=0x00;
PORTD=0xff;
LED_CONT=0;
TRISA=0x0f; //ADC enable
TRISB=0x00;
PORTB=0xff;
TRISC=0xff;
PORTC=0xff;
TRISE=0x00;
PORTE=0x07;
INTCON=0x00;
ADCON1=0x02;//set PORTE/PORTA
TRISB1=1;
TRISC7=1;
init_24c01();
init_LCM();
if(power_on)power_on_off();
now_key=FREQ_KEY;
for(xunhuan=0;;xunhuan++)
{
kkn++;
delay(255);
if(key)key_pro();
if(!(kkn&0x0f)){
read_key();
//read_bianma();
op_san_pro();
}
if(!(kkn&0x7)){
if(xunhuan)adc_pro();
}

if(key==0){
if(bianma)key=now_key;
}
if(!(xunhuan&0x7f)){
sys_display();
}

if(!FLAG_L){
if(mute_A){
ccn_A=64;
mute_A=0;
}
}
else {
ccn_A=0;
}
if(ccn_A)ccn_A--;
if(ccn_A==0){
mute_A=FLAG_L;
MUTE_L=!mute_A;
}
if(!FLAG_R){
if(mute_B){
ccn_B=64;
mute_B=0;
}
}
else {
ccn_B=0;
}
if(ccn_B)ccn_B--;
if(ccn_B==0){
mute_B=FLAG_R;
MUTE_R=!mute_B;
}
asm("clrwdt");//clrwdt();
}
}

搜索更多相关主题的帖子: bit PORTAIT static PORTC 
2007-07-29 14:23
jianweichief
Rank: 1
等 级:新手上路
帖 子:80
专家分:0
注 册:2007-7-18
收藏
得分:0 
the Lord will bless thee!

2007-07-29 16:21
cihren
Rank: 1
等 级:新手上路
帖 子:76
专家分:0
注 册:2007-6-27
收藏
得分:0 
我倒......

革命尚未成功,同志仍需努力!
2007-07-29 16:48
anlogo
Rank: 2
等 级:论坛游民
威 望:1
帖 子:293
专家分:20
注 册:2007-7-20
收藏
得分:0 
2007-07-29 17:18
快速回复:[求助]各位好!请帮助解释一下此程序,谢谢!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.026045 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved