程序如下,我使用的單片機有64字節RAM,這個程序卻需要133字節RAM,求解是程序本身這么大還是在哪里出了問題?
- #include <reg51.h>
- #include "intrins.h"
- #define unchar unsigned char
- #define unint unsigned int
- #define White 0xFFFFFF
- #define Black 0x000000
- #define Red 0x00fe00
- #define Blue 0x0000fe
- #define Green 0xfe0000
- #define nWs 20
- #define NOP()_nop_;
- unsigned long idata WsDat[nWs];
- unint Mod;
- sbit Din = P2^3;
- sbit key = P2^0;
- void delay(unint z) //1ms
- {
- unchar a,b;
- while(z--)
- for(b=118;b>0;b--)
- for(a=18;a>0;a--)
- ;
- }
- void h_dat0()
- {
- Din = 1;_nop_;
- Din = 0;_nop_;_nop_; _nop_;
- }
- void h_dat1()
- {
- Din = 1;_nop_;_nop_;_nop_;
- Din = 0;_nop_;
- }
- void Reset(void)
- {
- Din = 0;
- delay(1);
- }
- //發送一個字節
- void Send_Data(unsigned long LED_DAT)
- {
- unsigned char t;
-
- for(t=0;t<24;t++)
- {
- if(0x800000 == (LED_DAT & 0x800000) )
- {
- h_dat1();
- }
- else
- {
- h_dat0();
- }
- LED_DAT<<=1;
- }
- }
- //發送所有字節
- void WS_SetAll()
- {
- unsigned char j;
-
- for(j=0;j<nWs;j++)
- {
- Send_Data(WsDat[j]);
- }
- Reset();
- }
- //求絕對值
- unsigned char abs0(int num)
- {
- if(num<0)
- num = -num;
- return (unsigned char) num;
- }
- //顏色漸變算法
- unsigned long ColorToColor(unsigned long color0, unsigned long color1)
- {
- unsigned char Red0, Green0, Blue0;
- unsigned char Red1, Green1, Blue1;
- int RedMinus, GreenMinus, BlueMinus;
- unsigned char NStep;
- float RedStep, GreenStep, BlueStep;
- unsigned long color;
- unsigned char i;
-
- Red0 = color0>>8;
- Green0 = color0>>16;
- Blue0 = color0;
-
- Red1 = color1>>8;
- Green1 = color1>>16;
- Blue1 = color1;
-
- RedMinus = Red1 - Red0;
- GreenMinus = Green1 - Green0;
- BlueMinus = Blue1 - Blue0;
-
- if( abs0(RedMinus) > abs0(GreenMinus) )
- NStep=abs0(RedMinus);
- else
- NStep=abs0(GreenMinus);
- if( NStep < abs0(BlueMinus) )
- NStep=abs0(BlueMinus);
-
- RedStep = (float)RedMinus / NStep;
- GreenStep = (float)GreenMinus / NStep;
- BlueStep = (float)BlueMinus / NStep;
-
- for(i=0;i<NStep;i++)
- {
- Red1 = Red0 + (int)(RedStep * i);
- Green1 = Green0 + (int)(GreenStep * i);
- Blue1 = Blue0 + (int)(BlueStep * i);
-
- color = (((unsigned long)Green1<<16)&0XFF0000) | ((Red1<<8)&0XFF00) | Blue1&0XFF;
- WsDat[i] = color;
- WS_SetAll();
- delay(20);
- }
-
- return color;
- }
- void main()
- {
- while(1)
- {
-
- ColorToColor(Red,Green);
- }
-
- }
復制代碼
|