微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 嵌入式设计讨论 > MCU和单片机设计讨论 > 基于51的单片机波形发生器

基于51的单片机波形发生器

时间:10-02 整理:3721RD 点击:
#include<reg52.h>
#define uc unsigned char
#define ui unsigned int
sbit p10=P1^0;
sbit p11=P1^1;
sbit p12=P1^2;
sbit cs=P1^6;
sbit wr=P1^7;
sbit p33=P3^3;
sbit p32=P3^2;
ui p,fz,k;
ui num=1;
uc code DSY_CODE[]= {0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e,0x00};
uc code sin[64]={
135,145,158,167,176,188,199,209,218,226,234,240,245,249,252,254,254,253,251,247,243,237,230,222,213,204,193,182,170,158,
146,133,121,108,96,84,72,61,50,41,32,24,17,11,7,3,1,0,0,2,5,9,14,20,28,36,45,55,66,78,90,102,114,128
};
uc code juxing[64]={
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
};
uc code sanjiao[64]={
0,8,16,24,32,40,48,56,64,72,80,88,96,104,112,120,128,136,144,152,160,168,176,184,192,200,208,216,224,232,240,248,
248,240,232,224,216,208,200,192,184,176,168,160,152,144,136,128,120,112,104,96,88,80,72,64,56,48,40,32,24,16,8,0
};
void delay()
{
int a,b;
for(a=1;a>0;a--)
  for(b=122;b>0;b--);
}
void boxing() interrupt 0
{
  EX0=0;
  delay();
  if(p10==0) {p=1;P2=DSY_CODE[1];}
  else if(p11==0) {p=2;P2=DSY_CODE[2];}
  else if(p12==0) {p=3;P2=DSY_CODE[3];}
  delay();
  EX0=1;
}
void pinlv() interrupt 1
{
  int a;
  TH0=(65536-10)/256;
  TL0=(65536-10)/256;
  a=fz;
  if(fz--==0)
{
  if(p==1) P0=sin[k++];
  else if(p==2) P0=juxing[k++];
  else if(p==3) P0=sanjiao[k++];
}
  if(k==64) k=0;
  fz=a;
}  
void pinxuan() interrupt 2
{
  EX1=0;
  delay();
if(p33==0)
{
  num++;
  switch(num)
{
  case 1:fz=5;break;
  case 2:fz=100;break;
  case 3:fz=300;break;
  case 4:fz=500;break;
  case 5:fz=700;break;
  case 6:fz=900;break;
  case 7:fz=1000;break;
  default:num=1;break;
}
  delay();
  EX1=1;
}
}
  
void main()
{
  cs=0;
  wr=0;
  EA=1;
  TMOD=0x01;
  TH0=(65536-10)/256;
  TL0=(65536-10)/256;//10us定时
  IT0=1;
  EX0=1;
  IT1=1;
  EX1=1;
  while(1)
{
    delay();
    TR0=1;
    while(1);
}
}
   
  
哪有问题?逻辑上的错误?本人菜鸟,实在是看不出来了

好好好好好好好好好好

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top