|
下面是单片机测频的proteus仿真原理图(工程文件可到本帖附件中下载):
单片机源程序如下:
- //#include <reg51.h>
- #include <STC12C5A60S2.h>
- #define u8 unsigned char
- #define u16 unsigned int
- #define u32 unsigned long int
- #define vtime 3000 //定时3ms,一帧8*3=24ms,频率=40Hz
- #define jz12 //jz132 :晶振选择132.710400MH//jz12 :12MH
- #ifdef jz12
- //正常12MH
- #define t8s_n 90
- #define psv 4
- #else
- //132.7014MH
- #define t8s_n 1000
- #define psv 900
- #endif
- //void delay(void);
- //共阴数码管段码表
- u8 code distable[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0x00};
- //位选码表
- u8 code numi[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
- //显示缓存
- u8 V_ram[]={0,0,3,4,5,6,7,8};
- u8 Vm[]={0,0,3,4,5,6,7,8};
- u8 wi=0,mn=0,nt=0,wbs=0; //位选循环变量
- u8 t_l,t_h,bs=0;
- u32 adv=0,adsum=0;
- main() //m1:m0 00=标准; 01=推挽; 10=输入; 11=开漏输出
- {
- u16 i=0;
- u16 temp=0;
- //u32 temp0=0,temp1,temp2;
- //m1:m0 00=标准; 01=推挽; 10=输入; 11=开漏输出
- //P0M1 = 0X00;
- // P0M0 = 0Xff;
- P2M1 = 0X00;
- P2M0 = 0Xff; //设定P0,P2推挽输出
- //P3M1 = 0Xff;
- //P3M0 = 0X00;
- P1M1 = 0xff;
- P1M0 = 0x00;
- //TMOD = 0X50; //设定定时器0为16位计数方式
- //TH0 = (65536-vtime )/256;
- //TL0 = (65536-vtime )%256; //赋定时器0初值
- AUXR=0x80; //选择1T指令系统
- //ET0 = 1; //开定时器0中断
- //AUXR1=AUXR1|0x04;
- //P1ASF=0x01;
- //ADC_CONTR=0x80;
- //TR0=1;
- //PX1=1;
- //PX0=1;
- //PT1=1;
- //IT0=1;
- //IT1=1;
- //CCON = 0;
- //CL = 0;
- //CH = 0;
- //CMOD = 0X0F;
- //CCAP0H = 0X80;
- //CCAP0L = 0X80;
- //CCAPM0 = 0X42;
- //CCAPM1 = 0X00;
- //PCA_PWM0 = 0;
- //CR = 1;
- SPCTL=0xc5;
- …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码
给大家分享一些我们老师给的一些经典的单片机程序源码, 一共有十多个.都有详细的注释,然大家快速的理解每一行代码的意思。而且有proteus仿真原理图。大家可以直接验证程序的对错.
本系列所有源码打包下载地址(含proteus仿真工程文件和源程序):
http://www.51hei.com/bbs/dpj-82474-1.html
本例程下载:
SPI_slave.rar
(73.38 KB, 下载次数: 12)
|
|