|
本帖最後由 antlu 於 2012-7-7 03:26 PM 編輯
花了 59元人民幣託朋友從對岸買的套件,技術難度有一點高,以致於一拖再拖最後還是把基本程式寫了進去先跟大家分享, http://www.51dz.com/0/s---2489--.htm (十字旋轉LED 點陣套件) 困難度如下:
1. SMD IC 和 LED 電阻 電容器 焊接時候要防止 手抖 接腳短路...
2. 部分電路要自己加上小電路板
3. 感應以及馬達旋轉部分要自己加工
4. STC ISP 要自己做
5. 程式自己寫
電路圖:
STC ISP 線路圖參考
程式下載
這是我買8952實驗板附增的軟體
完成品
未下載程式時的現象
下載先前作的搖搖棒修改程式後
我的STC ISP 其實只用了 USB>>RS232的那一片黑色的小板子,其中電源要加裝一個開關.
背面 把USB>>RS232 輸出 4點 5V. TXD. RXD. GND
/*--2011.09.05 new
2012.07.04 修改給旋轉燈用
*/
#include<reg52.h>
#define UD P1// P0=顯示出上段8bit 的LED
#define DD P3// P2=顯示出下段8bit 的LED
//sbit vibrate_flag=P3^7;//水銀震動開關
//unsign char DspBF[14];//把顯示資料由此送出
unsigned char code DspBNK[73]={
0xff,0x7d,0x3d,0x5d,0x08,0x75,0x7d,0x7d,
0xfd,0x7d,0xf8,0x0d,0xfd,0xfd,0xff,0xff,
0x7d,0x3d,0x5d,0x08,0x75,0x7d,0x7d,0xfd,
0x7d,0xf8,0x0d,0xfd,0xfd,0xff,0xef,0xeb,
0xed,0x02,0xef,0x6f,0xed,0xc3,0x2f,0xeb,
0x6f,0xef,0xff,0x9f,0x0f,0x07,0x03,0x03,
0x07,0x0f,0x1f,0x0f,0x07,0x03,0x03,0x07,
0x0f,0x9f,0xff,0xbf,0x1f,0x8f,0xbf,0x1f,
0xbf,0xf7,0xf1,0xf7,0x07,0xf7,0xf7,0xe7,0xff };//15*5=75
unsigned char code DspBNK1[73]={
0xff,0xf3,0xfd,0xfe,0xe0,0xfe,0xfd,0xfb,
0xff,0xfc,0xdf,0xc0,0xff,0xff,0xff,0xff,
0xf3,0xfd,0xfe,0xe0,0xfe,0xfd,0xfb,0xff,
0xfc,0xdf,0xc0,0xff,0xff,0xff,0xef,0xf7,
0xfb,0xc0,0xfe,0xff,0xff,0xf7,0xf9,0xf8,
0xf7,0xef,0xff,0xff,0xff,0xfe,0xfc,0xf8,
0xf0,0xe0,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,
0xff,0xff,0xff,0xff,0xde,0xed,0xf3,0xec,
0xff,0xf9,0xfe,0xef,0xc0,0xff,0xfe,0xf9,0xf7 };//
/*--------------------------------------------------------------------------------------------
void Init_Timer0(void)
{
TMOD |= 0x01; //使用模式1,16位定時器,使用"|"符號可以在使用多個定時器並不受影響
TH0=0x0D8;//(65536-2000)/256; //重新設值2ms
TL0=0x0F0;//(65536-2000)%256;
EA=1; //
ET0=1; //
TR0=1; //TR0=0;不計時喔!!
}
//--------------------------------------------------------------------------------------------
void Timer0_isr(void) interrupt 1
{
TH0=0x0D8;//(65536-2000)/256;
TL0=0x0F0;//(65536-2000)%256;
counter++;//counter is Global variable.
if(counter==100) //10ms更新一次
{
counter=0;
TimeFlag=1; //計數器中斷約1秒時設定旗標為1,
//UpdateTimeFlag=1;//,定時計數器啟動用
}
}
*/
void DelayMs(unsigned char t);
//------------微秒延遲---------------------------------
void DelayUs2x(unsigned char t)
{
while(t--);
}
//--------------毫秒延遲--------------------------------
void DelayMs(unsigned char t)
{
while(t--);
{
DelayUs2x(245);
DelayUs2x(245);
}
}
/*void Out_A(void)
{
UD=DspBNK;
DD=DspBNK1;
DelayMs(1);
UD=0xff;
DD=oxff;
}
*/
void Display(void)
{
unsigned char k;
//必須要正反面掃描 反面需要把字反過來顯示(8*73)
while(1)
{
//if(!vibrate_flag)
/*
{
DelayMs(4);
for(k=0;k<73;k++)
{
UD=DspBNK[k];
DD=DspBNK1[k];
DelayUs2x(100);
UD=0xff;
DD=0xff;
DelayUs2x(10);
UD=DspBNK[k];
DD=DspBNK1[k];
DelayUs2x(100);
UD=0xff;
DD=0xff;
DelayUs2x(10);
UD=0xff;
DD=0xff;
DelayUs2x(30);
}
}*/
//if(vibrate_flag)
{
DelayMs(4);
for(k=73;k>0;k--)
{
UD=DspBNK[k];
DD=DspBNK1[k];
DelayUs2x(100);
UD=0xff;
DD=0xff;
DelayUs2x(10);
UD=DspBNK[k];
DD=DspBNK1[k];
DelayUs2x(100);
UD=0xff;
DD=0xff;
DelayUs2x(10);
UD=0xff;
DD=0xff;
DelayUs2x(30);
}
}
}
}
void main(void)
{
while(1)
{
Display();
}
}
此次製作中遇到幾個問題:
1.
使用自行產生器,以常態打開程式,因為是大陸的程式所以中文會產生亂碼無法看懂,但是功能正常,假如以大陸簡体打開程式就顯示正常,但是卻無法產生正常碼,於是兩個都開相互對照!!
2. 為了要同步顯示,所以要利用中断功能來作為同步,原來電路上的中断為 INT2(P4^3) 所以要增加 REG52.H 的內容,這也是第一次嘗試.
/*--------------------------------------------------------------------------
REG52.H
Header file for generic 80C52 and 80C32 microcontroller.
Copyright (c) 1988-2002 Keil Elektronik GmbH and Keil Software, Inc.
All rights reserved.
--------------------------------------------------------------------------*/
#ifndef __REG52_H__
#define __REG52_H__
/* BYTE Registers */
sfr P0 = 0x80;
sfr P1 = 0x90;
sfr P2 = 0xA0;
sfr P3 = 0xB0;
sfr PSW = 0xD0;
sfr ACC = 0xE0;
sfr B = 0xF0;
sfr SP = 0x81;
sfr DPL = 0x82;
sfr DPH = 0x83;
sfr PCON = 0x87;
sfr TCON = 0x88;
sfr TMOD = 0x89;
sfr TL0 = 0x8A;
sfr TL1 = 0x8B;
sfr TH0 = 0x8C;
sfr TH1 = 0x8D;
sfr IE = 0xA8;
sfr IP = 0xB8;
sfr SCON = 0x98;
sfr SBUF = 0x99;
/* 8052 Extensions */
sfr T2CON = 0xC8;
sfr RCAP2L = 0xCA;
sfr RCAP2H = 0xCB;
sfr TL2 = 0xCC;
sfr TH2 = 0xCD;
/*:) STC89LE51RC */
sfr XICON = 0xC0;
sbit EX2 = XICON^2;
sbit IT2 = XICON^0;
/* BIT Registers */
/* PSW */
sbit CY = PSW^7;
sbit AC = PSW^6;
sbit F0 = PSW^5;
sbit RS1 = PSW^4;
sbit RS0 = PSW^3;
sbit OV = PSW^2;
sbit P = PSW^0; //8052 only
/* TCON */
sbit TF1 = TCON^7;
sbit TR1 = TCON^6;
sbit TF0 = TCON^5;
sbit TR0 = TCON^4;
sbit IE1 = TCON^3;
sbit IT1 = TCON^2;
sbit IE0 = TCON^1;
sbit IT0 = TCON^0;
/* IE */
sbit EA = IE^7;
sbit ET2 = IE^5; //8052 only
sbit ES = IE^4;
sbit ET1 = IE^3;
sbit EX1 = IE^2;
sbit ET0 = IE^1;
sbit EX0 = IE^0;
/* IP */
sbit PT2 = IP^5;
sbit PS = IP^4;
sbit PT1 = IP^3;
sbit PX1 = IP^2;
sbit PT0 = IP^1;
sbit PX0 = IP^0;
/* P3 */
sbit RD = P3^7;
sbit WR = P3^6;
sbit T1 = P3^5;
sbit T0 = P3^4;
sbit INT1 = P3^3;
sbit INT0 = P3^2;
sbit TXD = P3^1;
sbit RXD = P3^0;
/* SCON */
sbit SM0 = SCON^7;
sbit SM1 = SCON^6;
sbit SM2 = SCON^5;
sbit REN = SCON^4;
sbit TB8 = SCON^3;
sbit RB8 = SCON^2;
sbit TI = SCON^1;
sbit RI = SCON^0;
/* P1 */
sbit T2EX = P1^1; // 8052 only
sbit T2 = P1^0; // 8052 only
/* T2CON */
sbit TF2 = T2CON^7;
sbit EXF2 = T2CON^6;
sbit RCLK = T2CON^5;
sbit TCLK = T2CON^4;
sbit EXEN2 = T2CON^3;
sbit TR2 = T2CON^2;
sbit C_T2 = T2CON^1;
sbit CP_RL2 = T2CON^0;
#endif
3.字型產生出來還要陰陽改變否則會一團"糊"
4. 字型產生出來卻 "顛倒顯示"這點還在想辦法突破!! 也希望高手可以指點!!
因為要把每一個BYTE 都改很辛苦 (原來 0X80 -->0X01..)
|
-
-
評分
-
6
查看全部評分
-
|