📄 ss_sweep.c
字号:
#include <absacc.h>
#include <reg52.h>
#include <stdlib.h>
#include <math.h>
#include <intrins.h>
#include "display_fun.h"
#include "ziku.h"
#include "wave.h"
#define uchar unsigned char
#define uint unsigned int
/*定义开关中断*/
#define DISABLE EA=0
#define ENABLE EA=1
#define ON 1
#define OFF 0
/*定义键盘*/
#define key0 0
#define key1 1
#define key2 2
#define key3 3
#define key4 4
#define key5 5
#define key6 6
#define key7 7
#define key8 8
#define key9 9
#define key_mod 10
#define key_clr 11
#define key_enter 12
#define key_tiao 13
#define key_xuan1 14
#define key_xuan2 15
/*define Command*/
#define Wsin 0
#define Wtri 1
#define Wpul 2
#define Wclr 3
/*定义端口,P2口用作控制线*/
sbit WR_M=P2^4; //回送M控制线
sbit RESET_PHASEREG=P2^5; //复位相位累加器
/*P1口用作LED显示线*/
sbit LED_CLK=P1^0; //LED时钟线
sbit LED_DAT=P1^1; //LED数据线
sbit Cmd_CS=P2^5;
sbit DC=P2^6;
sbit Mh=P2^7;
sbit Int_wire=P3^2;
uchar count=0; //显示的位数
bit flag=0; //是否按了ENTER,为0表示没有按
uchar idata value[5]={0,0,0,0,0}; //存储显示的数值
uchar mh_data=0; //送给CPLD的频率步进值高位
uchar ml_data=0; //送给CPLD的频率步进值低位
uchar idata key_pressed;
static uchar key_no;
void led_display(uchar i);
/*数字'1','2','3','4','5','6','7','8','9','0'的七段码字库*/
const uchar code LED_FONT[11]={ //
0xFC, //0
0x60, //1
0xDA, //2
0xF2, //3
0x66, //4
0xB6, //5
0xBE, //6
0xE0, //7
0xFE, //8
0xF6, //9
0x00 //不显示
};
void init_port()
{
uchar i;
P0 = 0xFF;
P1 = 0xFF;
RESET_PHASEREG=1; //禁止相位累加器工作
WR_M=1; //回送M控制线初始为高电平
Cmd_CS=1;
P3 = 0xFF;
for(i=0;i<6;i++)
led_display(10);
}
void init_interrupt()
{
IE=0x81;
PX0=1;
EX0=1;
IE0=0;
EA=1;
IT0=1; //外部中断0为跳变触发方式
ENABLE;
//CPU开中断
}
void led_display(uchar i)
{
uchar j,mask;
mask=0x01;
for(j=0;j<8;j++){
LED_CLK=0;
LED_DAT=( (LED_FONT[i]) & mask);
mask<<=1;
LED_CLK=1; //上升沿移位
}
}
void wait(void)
{
unsigned int i;
for(i=0;i<5000;i++);;
}
void delayMs(unsigned char dly)
{
unsigned char i;
unsigned int k;
for(i=dly;i!=0;i--)
{
for(k=0;k<1000;k++);
}
}
#define SysFrq 12
void SetPhase(unsigned long int Freq)
{
unsigned char div;
unsigned int phase;
#if SysFrq==12
if(Freq>31250)
{
Freq=31250;
value[0]=3;
value[1]=1;
value[2]=2;
value[3]=5;
value[4]=0;
}
if(Freq<1007)
{
div=31;
phase=Freq/0.4922;
}
if((Freq>=1007)&&(Freq<2081))
{
div=15;
phase=Freq/1.0173;
}
if((Freq>=2081)&&(Freq<4463))
{
div=7;
phase=Freq/2.1798;
}
if((Freq>=4463)&&(Freq<6249))
{
div=5;
phase=Freq/3.0517;
}
if((Freq>=6249)&&(Freq<7811))
{
div=4;
phase=Freq/3.8147;
}
if((Freq>=7811)&&(Freq<10415))
{
div=3;
phase=Freq/5.0863;
}
if((Freq>=10415)&&(Freq<15624))
{
div=2;
phase=Freq/7.6294;
}
if((Freq>=15624))
{
div=1;
phase=Freq/15.2588;
}
#endif
#if SysFrq==11
if(Freq>30316)
{
Freq=30316;
value[0]=3;
value[1]=0;
value[2]=3;
value[3]=1;
value[4]=6;
}
if(Freq<928)
{
div=31;
phase=Freq/0.4536;
}
if((Freq>=928)&&(Freq<1919))
{
div=15;
phase=Freq/0.9375;
}
if((Freq>=1919)&&(Freq<4113))
{
div=7;
phase=Freq/2.0090;
}
if((Freq>=4113)&&(Freq<5759))
{
div=5;
phase=Freq/2.8125;
}
if((Freq>=5759)&&(Freq<7199))
{
div=4;
phase=Freq/3.5156;
}
if((Freq>=7199)&&(Freq<10104))
{
div=3;
phase=Freq/4.9345;
}
if((Freq>=10104)&&(Freq<15157))
{
div=2;
phase=Freq/7.4017;
}
if((Freq>=30316))
{
div=1;
phase=Freq/14.8034;
}
#endif
P0=phase&0xff;//((unsigned char *)&phase)[1];
Mh=0;
DC=1;
Cmd_CS=1;
Cmd_CS=0;
Cmd_CS=1;
P0=(div<<3)|((phase&0x0700)>>8);//((unsigned char *)&phase)[0];
Mh=1;
DC=1;
Cmd_CS=1;
Cmd_CS=0;
Cmd_CS=1;
}
void SetCMD(unsigned char Cmd)
{
P0=Cmd;
DC=0;
Cmd_CS=1;
Cmd_CS=0;
Cmd_CS=1;
}
void refresh_led()
{
led_display(10);
led_display(value[0]);
led_display(value[1]);
led_display(value[2]);
led_display(value[3]);
led_display(value[4]);
}
#define AP 0x2a
/*
void display_mod(unsigned char mod)
{
Set_Display_Add(768);
printf("MOD:");
switch(mod)
{
case Wsin: printf("SIN ");
break;
case Wtri: printf("NONE ");
break;
case Wpul: printf("tiaofu");
break;
case Wclr: printf("NONE ");
break;
}
}*/
void display_mod(unsigned char mod)
{
unsigned int x=264 , y=24;
switch(mod)
{
case 0: showchinese(x,y,CD5FD);//正
x=x+16;
showchinese(x,y,CCFD2);//弦
x=x+16;
showchinese(x,y,CB2A8);//波
//showchinese(x+16,y,CCFD2);//弦
//showchinese(x+32,y,CB2A8);//波
initram_1();
show_123(1,sin);
break;
case 1: showchinese(x,y,CCEDE);//无
x=x+16;
showchinese(x,y,CD0C5);//信
x=x+16;
showchinese(x,y,CBAC5);//号
//showchinese(x+16,y,CD0C5);//信
//showchinese(x+32,y,CBAC5);//号
initram_1();
show_123(0,sin);
break;
case 2: showchinese(x,y,CCEDE);//无
x=x+16;
showchinese(x,y,CD0C5);//信
x=x+16;
showchinese(x,y,CBAC5);//号
//showchinese(x+16,y,CD0C5);//信
//showchinese(x+32,y,CBAC5);//号
initram_1();
show_123(0,sin);
break;
case 3: showchinese(x,y,CCEDE);//无
x=x+16;
showchinese(x,y,CD0C5);//信
x=x+16;
showchinese(x,y,CBAC5);//号
//showchinese(x+16,y,CD0C5);//信
//showchinese(x+32,y,CBAC5);//号
initram_1();
show_123(0,sin);
break;
default: break;
}
//show_wave(mod);
}
void show_fre(unsigned char a)
{
unsigned int x,y ;
switch(a)
{
case 0://显示频率值
x=264;y=184;
show_num(304,184,CC011);//H
show_num(312,184,CC012);//z
break;
case 1://显示最小值
x=80;y=220;
break;
case 2://显示最大值
x=128;y=220;// 176
break;
case 3://显示步长或系数
x=216;y=220;// 264
break;
default://清屏
x=264;y=184;
showchinese(x,y,C0000);
x=x+16;
showchinese(x,y,C0000);
x=x+16;
showchinese(x,y,C0000);
x=x+16;
showchinese(x,y,C0000);
/* showchinese(x+16,y,C0000);
showchinese(x+32,y,C0000);
showchinese(x+48,y,C0000);*/
return;
break;
}
show_num(x,y,CC000+(value[0]<<4));
x=x+8;
show_num(x,y,CC000+(value[1]<<4));
x=x+8;
show_num(x,y,CC000+(value[2]<<4));
x=x+8;
show_num(x,y,CC000+(value[3]<<4));
x=x+8;
show_num(x,y,CC000+(value[4]<<4));
/* show_num(x+8,y,CC000+(value[1]<<4));
show_num(x+16,y,CC000+(value[2]<<4));
show_num(x+24,y,CC000+(value[3]<<4));
show_num(x+32,y,CC000+(value[4]<<4));*/
}
void set_up(unsigned char flag)//flag=0,设置;flag=1,频率
{
unsigned int x=264,y=144;
switch(flag)
{
case 0:
showchinese(x,y,CC9E8);//设
x=x+16;
showchinese(x,144,CD6C3);//置
x=x+16;
show_num(x,144,CC010);//:
/* showchinese(264,144,CC9E8);//设
showchinese(264+16,144,CD6C3);//置
show_num(264+32,144,CC010);//:*/
break;
case 1:
showchinese(x,y,CC6B5);//频
x=x+16;
showchinese(x,144,CC2CA);//率
x=x+16;
show_num(x,144,CC010);//:
/* showchinese(264,144,CC6B5);//频
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -