单片机
返回首页

51单片机ADC0809函数信号发生器搭配4*4独立键盘

2025-09-29 来源:bilibili

#include <reg52.h>

#include<intrins.h>

#define uchar unsigned char

#define uint unsigned int

uchar delay=0;

uchar key,k;

uchar th0,tl0;

uchar pinlv=4679;

uchar N;

//zhengxianbo

uchar 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

};

//fangbo

uchar 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

};

//juchibo

uchar code juchi[64]={

0,4,8,12,16,20,24,28,32,36,40,45,49,53,57,61,65,69,73,77,81,85,89,93,97,101,105,109,113,117,121,125,130,134,138,142,

146,150,154,158,162,166,170,174,178,182,186,190,194,198,202,206,210,215,219,223,227,231,235,239,243,247,251,255

};

//sanjiaobo

uchar 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 delayms(uint xms)

{

 uint i,j;

 for(i=xms;i>0;i--)

 for(j=110;j>0;j--);

}

void matrixkeyscan()

{

 uchar temp;

 P1=0xfe;

 temp=P1;

 temp=temp&0xf0;

 if(temp != 0xf0)

 {

  delayms(10);

  temp=P1;

  temp=temp&0xf0;

  if(temp!=0xf0)

  {

   temp=P1;

   switch(temp)

   {

    case 0xee: 

             key=0;

              break; 

    case 0xde: 

              key=1;

              break; 

    case 0xbe: 

         key=2;

              break; 

    case 0x7e: 

         key=3;

              break;

   }

   while(temp!=0xf0)

   {

    temp=P1;

    temp=temp&0xf0;

   }

  }

 }

 P1=0xfd;

 temp=P1;

 temp=temp&0xf0;

 if(temp != 0xf0)

 {

  delayms(10);

  temp=P1;

  temp=temp&0xf0;

  if(temp!=0xf0)

  {

   temp=P1;

   switch(temp)

   {

    case 0xed: //pinlv+=1;

               //N=(unsigned long) 1000000/356/pinlv;

              pinlv+=1*15;

               th0=(65536-pinlv)/256;

               tl0=(65536-pinlv)%256;

               break; 

    case 0xdd: //pinlv+=10;

               //N=(unsigned long) 1000000/356/pinlv;

              pinlv+=10*15;

               th0=(65536-pinlv)/256;

               tl0=(65536-pinlv)%256;

               break; 

    case 0xbd: //pinlv+=50;

               //N=(unsigned long) 1000000/356/pinlv;

              pinlv+=50*15;

               th0=(65536-pinlv)/256;

               tl0=(65536-pinlv)%256;

               break; 

    case 0x7d: pinlv+=100;

               N=(unsigned long) 1000000/356/pinlv;

              //pinlv+=100*15;

               th0=(65536-pinlv)/256;

               tl0=(65536-pinlv)%256;

               break; 

   }

   while(temp!=0xf0)

   {

    temp=P1;

    temp=temp&0xf0;

   }

  }

 } 

 P1=0xfb;

 temp=P1;

 temp=temp&0xf0;

 if(temp != 0xf0)

 {

  delayms(10);

  temp=P1;

  temp=temp&0xf0;

  if(temp!=0xf0)

  {

   temp=P1;

   switch(temp)

   {

    case 0xeb:// pinlv-=1;

               //N=(unsigned long) 1000000/356/pinlv;

              pinlv+=1*15;

               th0=(65536-pinlv)/256;

               tl0=(65536-pinlv)%256;

               break; 

    case 0xdb: //pinlv-=10;

              // N=(unsigned long) 1000000/356/pinlv;

              pinlv+=10*15;

               th0=(65536-pinlv)/256;

               tl0=(65536-pinlv)%256;

               break; 

    case 0xbb: //pinlv-=50;

               //N=(unsigned long) 1000000/356/pinlv;

              pinlv+=50*15;

               th0=(65536-pinlv)/256;

               tl0=(65536-pinlv)%256;

               break; 

    case 0x7b: //pinlv-=100;

               //N=(unsigned long) 1000000/356/pinlv;

              pinlv+=100*15;

               th0=(65536-pinlv)/256;

               tl0=(65536-pinlv)%256;

               break;  

   }

   while(temp!=0xf0)

   {

    temp=P1;

    temp=temp&0xf0;

   }

  }

 }

 P1=0xf7;

 temp=P1;

 temp=temp&0xf0;

 if(temp != 0xf0)

 {

  delayms(10);

  temp=P1;

  temp=temp&0xf0;

  if(temp!=0xf0)

  {

   temp=P1;

   switch(temp)

   {

    case 0xe7: key=12;

               break; 

    case 0xd7: key=13;

               break; 

    case 0xb7: key=14;

               break; 

    case 0x77: key=15;

               break; 

   }

   while(temp!=0xf0)

   {

    temp=P1;

    temp=temp&0xf0;

   }

  }

 }

}

void main()

{

 TMOD=0x01;

  th0=(65536-pinlv)/256;

 tl0=(65536-pinlv)%256;

 TH0=th0;

 TL0=tl0;

 EA=1;

 IT0=1;

 EX0=1;

 IT1=1;

 EX1=1;

 ET0=1;

 TR0=1;

 pinlv=15;

 while(1)

 {

  matrixkeyscan();

 }

}

void time0() interrupt 1

{

 TH0=th0;

  TL0=tl0;

 switch(key)

 {

  case 0:

   P2=sin[k];

    k=(k+1)%64;

    break;

  case 1:

   P2=juxing[k];

    k=(k+1)%64;

    break;

  case 2:

   P2=juchi[k];

    k=(k+1)%64;

    break;

  case 3:

   P2=sanjiao[k];

    k=(k+1)%64;

    break;

  default: P2=0;

 }

}


进入单片机查看更多内容>>
相关视频
  • 【TI MSPM0 应用实战】智能小车+工业角度编码器+血氧仪+烟雾探测器!硬核参考设计详解!

  • 2022 Digi-Key KOL 系列: 你见过1GHz主频的单片机吗?Teensy 4.1开发板介绍

  • TI 新一代 C2000™ 微控制器:全方位助力伺服及马达驱动应用

  • MSP430电容触摸技术 - 防水Demo演示

  • 直播回放: Microchip Timberwolf™ 音频处理器在线研讨会

  • 基于灵动MM32W0系列MCU的指夹血氧仪控制及OTA升级应用方案分享

精选电路图
  • 1瓦线性调频增强器

  • 1瓦四级调频发射机

  • 500W MOS场效应管电源逆变器,12V转110V/220V

  • 红外开关

  • LM317过压保护

  • 0-30V/20A 大功率稳压电源(采用LM338)

    相关电子头条文章