lesson14_直流电机.rar

  • JKN9527
    了解作者
  • C/C++
    开发工具
  • 22KB
    文件大小
  • rar
    文件格式
  • 0
    收藏次数
  • 1 积分
    下载积分
  • 0
    下载次数
  • 2020-07-03 18:02
    上传日期
基于51单片机的直流电机控制,用矩阵按键启动或停止。
lesson14_直流电机.rar
  • lesson14_直流电机
  • lesson
    5.8KB
  • main.c
    3.1KB
  • lesson.uvopt
    54.7KB
  • lesson.lnp
    27B
  • lesson.M51
    8.1KB
  • lesson.uvproj
    12.9KB
  • lesson_uvopt.bak
    55.7KB
  • lesson_uvproj.bak
    12.9KB
  • lesson.hex
    1.6KB
  • lesson.plg
    334B
  • main.LST
    7.8KB
  • main.OBJ
    6.5KB
内容介绍
#include "reg51.h" #include "intrins.h" typedef unsigned char u8; typedef unsigned int u16; #define GPIO_KEY P0 sbit Motor=P1^0; sbit SER=P3^4; sbit RCLK=P3^5; sbit SRCLK=P3^6; u8 KeyValue; //矩阵按键键值 /*-- 文字: 开 --*/ /*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/ u8 code KaiDuan[]={0x80,0x82,0x82,0x82,0xFE,0x82,0x82,0x82,0x82,0x82,0xFE,0x82,0x82,0x82,0x80,0x00, 0x00,0x80,0x40,0x30,0x0F,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00}; /*-- 文字: 关 --*/ /*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/ u8 code GuanDuan[]={0x00,0x00,0x10,0x11,0x16,0x10,0x10,0xF0,0x10,0x10,0x14,0x13,0x10,0x00,0x00,0x00, 0x81,0x81,0x41,0x41,0x21,0x11,0x0D,0x03,0x0D,0x11,0x21,0x41,0x41,0x81,0x81,0x00}; /*-- 文字: O --*/ /*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/ u8 code OoDuan[]={0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00, 0x0F,0x10,0x20,0x20,0x20,0x10,0x0F,0x00,0x0F,0x10,0x20,0x20,0x20,0x10,0x0F,0x00}; u8 code LieDuan[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80}; void delay(u16 i) { while(i--); } void keyDown() //矩阵按键行列扫描 { u8 a=0; GPIO_KEY=0x0f; if(GPIO_KEY!=0x0f) { delay(1000); if(GPIO_KEY!=0x0f) { switch(GPIO_KEY) { case(0x07):KeyValue=1;break; case(0x0b):KeyValue=2;break; case(0x0d):KeyValue=3;break; case(0x0e):KeyValue=4;break; } GPIO_KEY=0xf0; switch(GPIO_KEY) { case(0x70):KeyValue=KeyValue;break; case(0xb0):KeyValue=KeyValue+4;break; case(0xd0):KeyValue=KeyValue+8;break; case(0xe0):KeyValue=KeyValue+12;break; } // while((a<50)&&(GPIO_KEY!=0xf0)) // { // delay(1000); // a++; // } } } } void Send74hc595(u8 dat1,u8 dat2,u8 dat3,u8 dat4) //74HC595串转并 { u8 i=0; for(i=0;i<8;i++) { SER=dat1>>7; dat1<<=1; SRCLK=0; _nop_(); _nop_(); SRCLK=1; } for(i=0;i<8;i++) { SER=dat2>>7; dat2<<=1; SRCLK=0; _nop_(); _nop_(); SRCLK=1; } for(i=0;i<8;i++) { SER=dat3>>7; dat3<<=1; SRCLK=0; _nop_(); _nop_(); SRCLK=1; } for(i=0;i<8;i++) { SER=dat4>>7; dat4<<=1; SRCLK=0; _nop_(); _nop_(); SRCLK=1; } RCLK=0; _nop_(); _nop_(); RCLK=1; } void main(void) { u8 i; while(1) { keyDown(); if((GPIO_KEY!=0x0F)&&((KeyValue>0)&&(KeyValue<17))) { if(KeyValue<9) { Motor=1; for(i=0;i<16;i++) { Send74hc595(~LieDuan[i+16],~LieDuan[i],KaiDuan[i+16],KaiDuan[i]); delay(10); } } else { Motor=0; for(i=0;i<16;i++) { Send74hc595(~LieDuan[i+16],~LieDuan[i],GuanDuan[i+16],GuanDuan[i]); delay(10); } } } else if(GPIO_KEY==0x0F) { Motor=0; for(i=0;i<16;i++) { Send74hc595(~LieDuan[i+16],~LieDuan[i],OoDuan[i+16],OoDuan[i]); delay(10); } } } }
评论
    相关推荐