📄 main.c
字号:
/*********************************************************************************************************
** 工程功能 :串口通信程序
** 工程作者 :Blue Sky Teams——ZZL
** 工程版本 :V1.0
*********************************************************************************************************/
#include<STC12C5A60S2.h>
#include<LCD1602.h>
#include<ADC.h>
#include<12864.h>
#define uchar unsigned char
#define uint unsigned int
#define FSCLK 11059200
//#define FSCLK 12000000
sbit k1=P3^6;//占空比1调整按键
sbit k2=P3^7;//占空比 2调整按键
sbit t1=P3^0;
sbit t2=P3^1;
sbit t3=P3^2;
sbit t4=P3^3;
char qq[]="z=";
int z1=75,z2=75;int yzw1,yzw2;int zzw1,zzw2;
float jz1;float jz2,jz3,jz4;
char ad1[]="u0= ";
char ad2[]="u1= ";
char ad3[]="u2= ";
char ad4[]="u3= ";
/*********************************************************************************************************
** 函数功能 :延时函数
** 函数说明 :利用软件延时,占用CPU,经调试最小单位大约为1ms
** 入口参数 :time:需要延时的时间,单位ms
** 出口参数 :无
*********************************************************************************************************/
void hzw()
{t1=1;
t2=0;t3=1;
t4=0;
z1=50;z2=75;
}
zzw()
{t1=1;
t2=0;t3=1;
t4=0;
z1=zzw1;z2=zzw2;
}
void yzw()
{t1=1;
t2=0;t3=1;
t4=0;
z1=yzw1;z2=yzw2;
}
void tc()
{t1=1;t2=1;t3=1;t4=1;
}
void qianji()
{ t1=1;
t2=0;t3=1;
t4=0;
z1=75;z2=75;
}
void zkb1(int i)
{ CCAP0H=CCAP0L=255*(100-i)/100;
lcd_pos(4,1);
lcd_wdat(0x30 + i/10);
lcd_wdat(0x30 + i%10);
//Write_1602_String("z=",0xc9);
//Write_1602_Data(0x30 + i/10);
//Write_1602_Data(0x30 + i%10);
}
void zkb2(int j)
{ CCAP1H=CCAP1L=255*(100-j)/100;
//Write_1602_String(",",0xcd);
lcd_pos(4,3);
lcd_wdat(0x30 + j/10);
lcd_wdat(0x30 + j%10);
//Write_1602_Data(',');
//Write_1602_Data(0x30 + j/10);
//Write_1602_Data(0x30 + j%10);
}
void Delay_ms(uint time)
{
uint i,j;
for(i = 0;i < time;i ++)
for(j = 0;j < 930;j ++);
}
void main()
{
float res0,res1,res2,res3;
yzw1=75;yzw2=67;zzw1=67;zzw2=75;
CCON=0;
CL=0;
CH=0;
CMOD=0x08;//时钟源为系统时钟,故pwm的频率为系统时钟/256
CCAP0H=CCAP0L=0x80;//设置占空比为50%
CCAPM0=0x42;//允许比较功能,且设置pwm0的输出口为P1.3
CCAP1H=CCAP1L=0x80;
CCAPM1=0x42;//允许比较功能,且设置pwm1的输出口为P1.4
CR=1;//启动计数
lcd_init();
//LCD_1602_Init(); //液晶显示前进行初始化
ADC_Init(ADC_PORT0 | ADC_PORT1); //配置通道P1^0 ,P1^1 为AD采集口,如要配置其他其他口,直接用或运算加进初始化函数中
//Write_1602_String("ADC TEST",0xc0 + 0x04);
//t1=1;
//t2=0;t3=1;t4=0;
jz1=GetADCResult(ADC_CH2);
jz2=GetADCResult(ADC_CH6);
jz3=GetADCResult(ADC_CH7);
jz4=GetADCResult(ADC_CH5);
Delay_ms(5);
lcd_pos(4,0);
lcd12864(qq);
while(1)
{
if(k1==0)
{zzw1++;
if(zzw1==100)
zzw1=0;}
if(k2==0)
{yzw2++;
if(yzw2==100)
yzw2=0;}
zkb1(z1); //占空比为60%
zkb2(z2); //占空比为80%
res0=GetADCResult(ADC_CH6); // //通道1 AD
lcd_pos(1,0);
ad1[3]= 0x30 + (uint)res0%10;
ad1[4]='.';
ad1[5]=0x30 + (uint)(res0*10)%10;
ad1[6]=0x30 + (uint)(res0*100)%10;
ad1[7]=0x30 + (uint)(res0*1000)%10;
lcd12864(ad1);
res1=GetADCResult(ADC_CH7); //通道2 AD
lcd_pos(1,4);
ad2[3]= 0x30 + (uint)res1%10;
ad2[4]='.';
ad2[5]=0x30 + (uint)(res1*10)%10;
ad2[6]=0x30 + (uint)(res1*100)%10;
ad2[7]=0x30 + (uint)(res1*1000)%10;
lcd12864(ad2);
//Write_1602_Data('V');
Delay_ms(100);
res2=GetADCResult(ADC_CH2); //通道3 AD
lcd_pos(2,0);
ad3[3]= 0x30 + (uint)res2%10;
ad3[4]='.';
ad3[5]=0x30 + (uint)(res2*10)%10;
ad3[6]=0x30 + (uint)(res2*100)%10;
ad3[7]=0x30 + (uint)(res2*1000)%10;
lcd12864(ad3);
res3=GetADCResult(ADC_CH5); //通道3 AD
lcd_pos(2,4);
ad4[3]= 0x30 + (uint)res3%10;
ad4[4]='.';
ad4[5]=0x30 + (uint)(res3*10)%10;
ad4[6]=0x30 + (uint)(res3*100)%10;
ad4[7]=0x30 + (uint)(res3*1000)%10;
lcd12864(ad4);
//Write_1602_Data('V');
//Write_1602_String("U2=",0xc0);
//Write_1602_Data(0x30 + (uint)res2%10);
//Write_1602_Data('.');
//Write_1602_Data(0x30 + (uint)(res2*10)%10);
//Write_1602_Data(0x30 + (uint)(res2*100)%10);
//Write_1602_Data(0x30 + (uint)(res2*1000)%10);
//Write_1602_Data('V');
Delay_ms(10);
if((jz1>=res2)&&(jz3>=res1)||(res2*10-jz1*10>13))
tc();
if((res2*100-jz1*100>=19)&&((res1*10-jz3*10)<=(res2*10-jz1*10))&&(res2*10-jz1*10<13))
qianji();
if((res1*10-jz3*10>=1)&&((res1*10-jz3*10)>=(res2*10-jz1*10))&&(res2*10-jz1*10<13))
yzw();
if((res0*10-jz2*10>=1)&&((res0*10-jz2*10)>=(res2*10-jz1*10))&&(res2*10-jz1*10<13))
zzw();
if((res3*100-jz4*100>=15))
hzw();
}
}
/************************** (C) COPYRIGHT 2011 Blue Sky Teams *****END OF FILE*****************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -