Showing posts with label SDCC. Show all posts
Showing posts with label SDCC. Show all posts
Friday, June 18, 2010
Common Interrupt Pitfalls
SDCC Compiler User Guide ထဲမှာ ပါတဲ့ စိတ်ဝင်စား စရာ အချက်တချို့ကို ပြန်ပြော ချင်ပါတယ်။
ကျွန်တော့် အတွေ့အကြုံ အရ အဲဒီ အချက်တွေဟာ အရမ်းအရေး ကြီးပြီး firmware programmer တွေအတွက် အမြဲခေါင်းထဲမှာ ရှိနေဖို့ လိုတယ် လို့ ထင်ပါတယ်။
တစ်ခါက ကျွန်တော့် ပရိုဂရမ် မှာ ဘာ အမှားမှ မရှိပဲ သူ့ကို သုံးတဲ့အခါ တလွဲတွေပဲ လုပ်နေပါတယ်။ Stack overflow ဖြစ်နိုင်တာ ကို ရုတ်တရက် သတိရ ပြီး Stack အရွယ်အစား ပြင်လိုက်တဲ့ အခါ ကောင်းသွားတာ မျိုး မကြာခဏ ကြုံဖူးပါတယ်။
Tuesday, August 18, 2009
SDCC - Small Device C Compiler
SDCC - Small Device C Compiler က အလကား ရနိုင်တဲ့ free open source C compiler ပါ။ သူက 8051 နဲ့ အခြား microcontroller အချို့အတွက်ပါ။
SDCC လို အလကား မဟုတ်ပဲ ပိုက်ဆံ ပေးဝယ်ရတဲ့ အခြား Keil တို့လို compiler တွေလဲ ရှိပါတယ်။ အဲဒီမှာ free evaluation version ကိုရနိုင်ပေမယ့် အစမ်းသဘော အတွက်ပဲ ရည်ရွယ်ပြီး code size ကို 2k byte ထက် ပိုသုံးလို့ မရအောင် ကန့်သတ်ထားပါတယ်။ SDCC ရဲ့ကောင်းတဲ့ အချက်ကတော့ ပိုက်ဆံ တစ်ပြားမှ မကုန်ပဲ အလကား ရနိုင်တာပါ။ ဒီမှာ ပြောမှာ ကတော့ SDCC manual ကို အကျဉ်းချုံး ထုတ်နုတ်ပြော တာပါ။
Installing
http://sdcc.sourceforge.net/ ကိုသွားပြီး setup program ကို download လုပ်နိုင်ပါတယ်။ နောက် setup program ကို Run ပါ။
Testing the SDCC Compiler
နောက် command prompt ကိုသွားပြီး compiler အလုပ် လုပ်မလုပ် စမ်းကြည့်ဖို့ "sdcc -v" ကို enter လုပ်ပါ။ SDCC ကသူ့ရဲ့ ဗားရှင်း နံပါတ်ကို reply ပြန်တာ ကို တွေ့ ရပါလိမ့် မယ်။
Example C Program
အောက် ပါ နမူနာ program ကို စိတ်ကြိုက် ASCII editor တစ်ခုခု သုံးပြီး ရိုက်ပါ။ ထို့နောက် led.c အမည်ဖြင့် သိမ်းပါ။ Eclipse အစရှိတဲ့ development IDE တွေသုံးလို့ လဲရပါတယ်။ အဲဒီ အကြောင်း ကြုံရင် ပြောပါမယ်။ ဒီနမူနာ က 8051 microcontroller ရဲ့ P3.4 pin ကိုဆက်သွယ်ထား တဲ့ LED ကို မှိတ်တုပ် မှိတ်တုပ် အဖွင့် အပိတ် လုပ်ပေးဖို့ ပါ။
Compiling and Getting Hex File
command prompt မှာ ဖိုင် led.c ရှိတဲ့ နေရာကို သွားပြီး "sdcc led.c" ကို enter လုပ်ပါ။ အားလုံး အဆင်ပြေရင် အမှား မတက်ပဲ led.ihx ဆိုတဲ့ဖိုင် ထွက်လာပါမယ်။ "dir" ကို enter လုပ်ပြီး အဲဒီဖိုင် ထွက်မထွက် ကြည့်နိုင်ပါတယ်။ နောက် သင့်ရဲ့ chip ထဲကို download လုပ်ဖို့ သင့်တော်တဲ့ intel hex file ရအောင် "packihx led.ihx>led.hex" ကို enter လုပ်ပါ။ ထွက်လာတဲ့ led.hex ကို သုံးလို့ ရပါပြီ။
Projects with Multiple Source Files
SDCC က တစ်ကြိမ်မှာ တစ်ဖိုင် ပဲ compile လုပ်ပေးနိုင်ပါတယ်။ ဥပမာ main.c blink.c ဆိုတဲ့ ဖိုင်တွေရှိ တဲ့ project ကို စမ်းဖို့ အောက်ပါ အတိုင်း ရိုက်ထည့်ပြီး ဖိုင် များကို ဖန်တီးပါ။
main() function မပါတဲ့ ဖိုင်များကို "sdcc -c blink.c" ဆိုတဲ့ command သုံးပြီး သပ်သပ် compile လုပ်ပါ။ နောက် main() function ပါတဲ့ ဖိုင်ကို နောက်ဆုံးမှ "sdcc main.c blink.rel" ဆိုတဲ့ ပုံစံ အတိုင်း compile လုပ်နိုင်ပါတယ်။ main.ihx ဆိုတဲ့ ဖိုင်ထွက်လာမှာ ဖြစ်ပြီး ထုံးစံ အတိုင်း main.hex ကို ရယူ အသုံးပြု နိုင်ပါတယ်။
Installing
http://sdcc.sourceforge.net/ ကိုသွားပြီး setup program ကို download လုပ်နိုင်ပါတယ်။ နောက် setup program ကို Run ပါ။
Testing the SDCC Compiler
နောက် command prompt ကိုသွားပြီး compiler အလုပ် လုပ်မလုပ် စမ်းကြည့်ဖို့ "sdcc -v" ကို enter လုပ်ပါ။ SDCC ကသူ့ရဲ့ ဗားရှင်း နံပါတ်ကို reply ပြန်တာ ကို တွေ့ ရပါလိမ့် မယ်။
Example C Program
အောက် ပါ နမူနာ program ကို စိတ်ကြိုက် ASCII editor တစ်ခုခု သုံးပြီး ရိုက်ပါ။ ထို့နောက် led.c အမည်ဖြင့် သိမ်းပါ။ Eclipse အစရှိတဲ့ development IDE တွေသုံးလို့ လဲရပါတယ်။ အဲဒီ အကြောင်း ကြုံရင် ပြောပါမယ်။ ဒီနမူနာ က 8051 microcontroller ရဲ့ P3.4 pin ကိုဆက်သွယ်ထား တဲ့ LED ကို မှိတ်တုပ် မှိတ်တုပ် အဖွင့် အပိတ် လုပ်ပေးဖို့ ပါ။
#include<8052.h>
void main()
{
int i;
while(1)
{
P3_4=0; //Output 0
for(i=0;i<30000;i++); //delay loop
P3_4=1; //Output 1
for(i=0;i<30000;i++); //delay loop
}
}
Compiling and Getting Hex File
command prompt မှာ ဖိုင် led.c ရှိတဲ့ နေရာကို သွားပြီး "sdcc led.c" ကို enter လုပ်ပါ။ အားလုံး အဆင်ပြေရင် အမှား မတက်ပဲ led.ihx ဆိုတဲ့ဖိုင် ထွက်လာပါမယ်။ "dir" ကို enter လုပ်ပြီး အဲဒီဖိုင် ထွက်မထွက် ကြည့်နိုင်ပါတယ်။ နောက် သင့်ရဲ့ chip ထဲကို download လုပ်ဖို့ သင့်တော်တဲ့ intel hex file ရအောင် "packihx led.ihx>led.hex" ကို enter လုပ်ပါ။ ထွက်လာတဲ့ led.hex ကို သုံးလို့ ရပါပြီ။
Projects with Multiple Source Files
SDCC က တစ်ကြိမ်မှာ တစ်ဖိုင် ပဲ compile လုပ်ပေးနိုင်ပါတယ်။ ဥပမာ main.c blink.c ဆိုတဲ့ ဖိုင်တွေရှိ တဲ့ project ကို စမ်းဖို့ အောက်ပါ အတိုင်း ရိုက်ထည့်ပြီး ဖိုင် များကို ဖန်တီးပါ။
//File name: main.c
#include "blink.h"
void main()
{
while(1)
{
toggle();
delay();
}
}
//File name: blink.c
#include <8052.h>
#include "blink.h"
void toggle()
{
P3_4^=1;
}
void delay()
{
int i;
for(i=0;i<30000;i++); //delay loop
}
//File name: blink.h void toggle(); void delay();
main() function မပါတဲ့ ဖိုင်များကို "sdcc -c blink.c" ဆိုတဲ့ command သုံးပြီး သပ်သပ် compile လုပ်ပါ။ နောက် main() function ပါတဲ့ ဖိုင်ကို နောက်ဆုံးမှ "sdcc main.c blink.rel" ဆိုတဲ့ ပုံစံ အတိုင်း compile လုပ်နိုင်ပါတယ်။ main.ihx ဆိုတဲ့ ဖိုင်ထွက်လာမှာ ဖြစ်ပြီး ထုံးစံ အတိုင်း main.hex ကို ရယူ အသုံးပြု နိုင်ပါတယ်။
Subscribe to:
Posts (Atom)