<img src="img/veclock.jpg" alt="veclock">
最近玩MCU,玩着玩着遇到了该死的PWM,做了好久的实验也没有成功,遂转换心情来驱动下 F5461BH 。
之前还以为上网查查就可以找到相应的引脚图,不料却难以找到这些东西,然后自己一个个的试。。。。。。
然后花了两个小时,都琢磨透了。
PS: a、b、c、d 从左到右数。 最右边的引脚是 中间的那两个点,具体用法你慢慢钻研吧(也不难,一个接高电平一个接低电平就可以点亮了)
原理: F5461BH是一个共阳4位的8段数码管,下图的数字对应上图的。
不过值得注意的是,这些数字对应的都得接上低电平,好像是因为共阳的关系。。。。。。
这个已经很详细了,怎么搞你们懂得。。。。。。
另外附上驱动代码(STC12C2052AD)
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198//#include <REG51.h>//#include <REG52.h>#include <STC11Fxx.H>//#include <STC12C2052AD.h>sbit l8 = P1 ^ 0;sbit l7 = P1 ^ 1;sbit l6 = P1 ^ 2;sbit l5 = P1 ^ 3;sbit l4 = P1 ^ 4;sbit l3 = P1 ^ 5;sbit l2 = P1 ^ 6;sbit l1 = P1 ^ 7;char bufbit[4] = {1, 2, 3, 4};#define RFR 3 //Refresh Ratesbit ba = P3 ^ 2;sbit bb = P3 ^ 3;sbit bc = P3 ^ 4;sbit bd = P3 ^ 5;/************************************************************** ºÁÃ뼶ÑÓʱº¯Êý *µ÷Óú¯Êý±ØÐë¸øÑÓʱº¯ÊýÒ»¸ö0~65535µÄÑÓʱֵ¶ÔÓ¦0MSµ½65535MS/*************************************************************/void Delay (unsigned int a){ //ÐèÒªÊäÈë±äÁ¿Öµ0~65535 unsigned int i; while( --a != 0){ //i ´Ó0¼Óµ½600£¬CPU´ó¸Å¾ÍºÄʱ1ºÁÃë for(i = 0; i < 600; i++); //¿ÕÖ¸ÁîÑ»· }}int shown(int num){ l1 = 1; l2 = 1; l3 = 1; l4 = 1; l5 = 1; l6 = 1; l7 = 1; l8 = 1; switch(num){ case 0: l1 = 0; l2 = 0; l3 = 0; l4 = 1; l5 = 0; l6 = 0; l7 = 0; l8 = 1; break; case 1: l1 = 1; l2 = 1; l3 = 0; l4 = 1; l5 = 1; l6 = 0; l7 = 1; l8 = 1; break; case 2: l1 = 0; l2 = 1; l3 = 0; l4 = 0; l5 = 0; l6 = 1; l7 = 0; l8 = 1; break; case 3: l1 = 0; l2 = 1; l3 = 0; l4 = 0; l5 = 1; l6 = 0; l7 = 0; l8 = 1; break; case 4: l1 = 1; l2 = 0; l3 = 0; l4 = 0; l5 = 1; l6 = 0; l7 = 1; l8 = 1; break; case 5: l1 = 0; l2 = 0; l3 = 1; l4 = 0; l5 = 1; l6 = 0; l7 = 0; l8 = 1; break; case 6: l1 = 0; l2 = 0; l3 = 1; l4 = 0; l5 = 0; l6 = 0; l7 = 0; l8 = 1; break; case 7: l1 = 0; l2 = 1; l3 = 0; l4 = 1; l5 = 1; l6 = 0; l7 = 1; l8 = 1; break; case 8: l1 = 0; l2 = 0; l3 = 0; l4 = 0; l5 = 0; l6 = 0; l7 = 0; l8 = 1; break; case 9: l1 = 0; l2 = 0; l3 = 0; l4 = 0; l5 = 1; l6 = 0; l7 = 0; l8 = 1; break; default: break; }}void initbit(){ ba = 0; bb = 0; bc = 0; bd = 0;}void disba(){ initbit(); ba = 1; shown(bufbit[0]);}void disbb(){ initbit(); bb = 1; shown(bufbit[1]);}void disbc(){ initbit(); bc = 1; shown(bufbit[2]);}void disbd(){ initbit(); bd = 1; shown(bufbit[3]);}void display(){ Delay(RFR); disba(); Delay(RFR); disbb(); Delay(RFR); disbc(); Delay(RFR); disbd();} void main (void){ P3M0 = 0xfc; P3M1 = 0x00; ba = 1; bb = 1; bc = 1; bd = 1;// bufbit = { 1, 2, 3, 4}; while(1){ display(); //shown(a); }}// 感谢 Delay 函数由 DoYoung 提供。
驱动引脚的接法(STC12C2052AD):
好像没了吧? KEIL 2 工程下载地址: http://pan.baidu.com/s/1jK6qM