下面这些凌阳SPCE061A十六位单片机的程序 都是我在开发板上通过硬件反复调试通过的,大家可随便拿去用,有问题可与我联系哦,我在51hei的id是ikedge.
第一个能用的程序:
点亮IOA的低八位
//新建一个***.asm文件 .include hardware.inc; //头文件的格式 .PUBLIC _main //全局 .code //定义在代码段 _main: r1=0x00FF [P_IOA_Dir]=r1 //方向输出 r1=0x0055 [P_IOA_Buffer]=r1 //输出 r1=0x00FF [P_IOA_Attrib]=r1 //同向输出 用4HZ的中断闪烁led .include hardware.inc; .PUBLIC _main .code _main: r1=0x00FF [P_IOA_Dir]=r1 r1=0x0055 [P_IOA_Buffer]=r1 r1=0x00FF [P_IOA_Attrib]=r1 INT IRQ r3=0x0008 [P_INT_Ctrl]=r3 //打开IRQ5中断 //r2=0x002D //[P_TimerA_Ctrl]=r2 //选择2Hz的中断 .TEXT .public _IRQ5 _IRQ5: r4=0x00FF [P_IOA_Dir]=r4 r4=0x00AA [P_IOA_Buffer]=r4 r4=0x00FF [P_IOA_Attrib]=r4 RETI; 经过修改的十六位控制八位流水灯 .include hardware.inc; .PUBLIC _main //.PUBLIC _loop .code _main: // r1=0x00FF // [P_IOA_Dir]=r1 // r1=0x0055 // [P_IOA_Buffer]=r1 // r1=0x00FF // [P_IOA_Attrib]=r1 r4=0x0001 INT IRQ //打开中断开关 r3=0x1000 [P_INT_Ctrl]=r3 //打开IRQ1对应的timerA的中断 r2=0x0034 [P_TimerA_Ctrl]=r2 //选择4096Hz频率自加溢出的中断 //r2=0xf000 //1second r2=0xfe57 //0.1second //r2=0xe000 //2second //r2=0xf800 //0.5second //r2=0xfffe [P_TimerA_Data]=r2 //置初值f800/634Loop _loop: r5 = 0x0001 [P_Watchdog_Clear] = r5 goto _loop .TEXT .public _IRQ1 _IRQ1: r1=0x00FF [P_IOA_Dir]=r1 r1=0x00FF [P_IOA_Attrib]=r1 r4=r4 LSL 1 r4=r4&0x00ff CMP r4 ,0x0000 jz _loop1 jmp _loop2 _loop1: r4=0x0001 _loop2: [P_IOA_Data]=r4 r1=0x1000 [P_INT_Clear]=r1 //r5 = 0x0001 // [P_Watchdog_Clear] = r5 RETI; 使用系统时钟计数的流水灯 .include hardware.inc; .PUBLIC _main //.PUBLIC _loop .code _main: // r1=0x00FF // [P_IOA_Dir]=r1 // r1=0x0055 // [P_IOA_Buffer]=r1 // r1=0x00FF // [P_IOA_Attrib]=r1 //r1=0x0073 //fosc频率是40.96M CPU频率是fosc/8 //r1=0x0033 //fosc频率是20.48M CPU频率是fosc/8 r1=0x0013 //fosc频率是24.576M CPU频率是fosc/8 //r1=0x0063 //fosc频率是32.768M CPU频率是fosc/8 //r1=0x00f3 //fosc频率是49.152M CPU频率是fosc/8 //r1=0x00f0 //fosc频率是49.152M CPU频率是fosc [P_SystemClock]=r1 r4=0x0001 INT IRQ //打开中断开关 r3=0x1000 [P_INT_Ctrl]=r3 //打开IRQ1对应的timerA的中断 r2=0x0031 //选择fosc/256的频率自加 [P_TimerA_Ctrl]=r2 //选择4096Hz频率自加溢出的中断 //r2=0xf000 //1second //r2=0xfe57 //0.1second //r2=0xe000 //2second //r2=0xf800 //0.5second r2=0x0000 [P_TimerA_Data]=r2 //置初值f800/634Loop _loop: r5 = 0x0001 [P_Watchdog_Clear] = r5 goto _loop .TEXT .public _IRQ1 _IRQ1: r1=0x00FF [P_IOA_Dir]=r1 r1=0x00FF [P_IOA_Attrib]=r1 r4=r4 LSL 1 r4=r4&0x00ff CMP r4 ,0x0000 jz _loop1 jmp _loop2 _loop1: r4=0x0001 _loop2: [P_IOA_Data]=r4 r1=0x1000 [P_INT_Clear]=r1 //r5 = 0x0001 // [P_Watchdog_Clear] = r5 RETI; IOB08作为PWM输出 .include hardware.inc; .PUBLIC _main //.PUBLIC _loop .code _main: r1=0xFFFF [P_IOB_Dir]=r1 r1=0xFFFF [P_IOB_Attrib]=r1 r1=0x0000 [P_IOA_Buffer]=r1 //r1=0x0073 //fosc频率是40.96M CPU频率是fosc/8 //r1=0x0033 //fosc频率是20.48M CPU频率是fosc/8 r1=0x0013 //fosc频率是24.576M CPU频率是fosc/8 //r1=0x0063 //fosc频率是32.768M CPU频率是fosc/8 //r1=0x00f3 //fosc频率是49.152M CPU频率是fosc/8 //r1=0x00f0 //fosc频率是49.152M CPU频率是fosc [P_SystemClock]=r1 r4=0x0001 INT IRQ //打开中断开关 r3=0x1000 [P_INT_Ctrl]=r3 //打开IRQ1对应的timerA的中断 r2=0x0071 //选择fosc/256的频率自加 [P_TimerA_Ctrl]=r2 //选择4096Hz频率自加溢出的中断 //r2=0xf000 //1second //r2=0xfe57 //0.1second //r2=0xe000 //2second //r2=0xf800 //0.5second r2=0xfff0 [P_TimerA_Data]=r2 //置初值f800/634Loop _loop: r5 = 0x0001 [P_Watchdog_Clear] = r5 goto _loop .TEXT .public _IRQ1 _IRQ1: r1=0x00FF [P_IOA_Dir]=r1 r1=0x00FF [P_IOA_Attrib]=r1 r4=r4 LSL 1 r4=r4&0x00ff CMP r4 ,0x0000 jz _loop1 jmp _loop2 _loop1: r4=0x0001 _loop2: [P_IOA_Data]=r4 r1=0x1000 [P_INT_Clear]=r1 //r5 = 0x0001 // [P_Watchdog_Clear] = r5 RETI; // 工程名称:ADC_LINE.scs // 功能描述: 通过改变LINE_IN端口的模拟电压来改变IOB口输出的数据, // 采用自动方式即定时器A溢出执行ADC转换,可以通过发光 // 二极管的点亮了解转换的数据值。 // 硬件连接:IOB口的高8位连接发光二极管 //============================================================ // 文件名称:ADC_LINE.asm // 实现功能: 通过改变LINE_IN端口的模拟电压来改变IOB口输出的数据, // 采用自动方式即定时器A溢出执行ADC转换,可以通过发光 // 二极管的点亮了解转换的数据值。 //============================================================ .DEFINE P_IOB_DATA 0x7005 .DEFINE P_IOB_DIR 0x7007 .DEFINE P_IOB_ATTRI 0x7008 .DEFINE P_INT_Ctrl 0x7010 .DEFINE P_INT_CLEAR 0x7011 .DEFINE P_ADC_Ctrl 0x7015 .DEFINE P_ADC_MUX_Ctrl 0x702b .DEFINE P_ADC_MUX_DATA 0x702C .DEFINE P_DAC_Ctrl 0x702A .DEFINE P_WATCHDOG_CLEAR 0x7012 .CODE //============================================================= // 函数名称: _main // 功能描述: 通过改变LINE_IN端口的模拟电压来改变IOB口输出的数据, // 采用自动方式即定时器A溢出执行ADC转换,可以通过发光 // 二极管的点亮了解转换的数据值。 // 语法格式: _main //入口参数: 无 // 出口参数: 无 // 注意事项: 仅为用户模型 //================================================================= .PUBLIC _main _main: r1 = 0xffff [P_IOB_ATTRI] = r1 //IOB口设置为同相输出口 [P_IOB_DIR] = r1 r1 = 0x0000 [P_IOB_DATA] = r1; r1 = 0x0001 //选择通道LINE_IN为IOA4 [P_ADC_MUX_Ctrl] = r1 r1 = 0x0001 //允许A/D转换 [P_ADC_Ctrl] = r1 L_AD: r1 = [P_ADC_MUX_Ctrl] //读寄存器[P_ADC_MUX_Ctrl]的B15位 test r1,0x8000 //判断是否转换完毕 jz L_AD //否,继续转换 r1 = [P_ADC_MUX_DATA] //是,则读出[P_ADC_MUX_DATA]转换结果 [P_IOB_DATA] = r1 //同时触发A/D重新转换 r1 = 0x0001 [P_WATCHDOG_CLEAR] = r1 //清看门狗 jmp L_AD; 用C语言编的第一个程序 #include "hardware.h" int main() { unsigned int i, j=0; for (i=0;i<=100;i++) j = j + i; //G_Su保存果 while(1) //程序结束循环 { unsigned int ClearWatchdog =0x7012; ClearWatchdog = 0x0001; //清看门狗 } } 包括IOA口初始化子函数 #include "hardware.h" #define Port_IOA_Data 0x7000 //portA data #define Port_IOA_Buffer 0x7001 //portA buffer #define Port_IOA_Dir 0x7002 //portAdirection #define Port_IOA_Attrib 0x7003 unsigned int _Port_IOA_Attrib , _Port_IOA_Dir, _Port_IOA_Data, _Port_IOA_Buffer; int main() { IOA_Init(); while(1) //程序结束循环 { unsigned int ClearWatchdog = 0x7012; ClearWatchdog = 0x0001; //清看门狗 } } void IOA_Init() //IOA口初始化 { //=============================== _Port_IOA_Dir=0xFFF; _Port_IOA_Attrib=0xFFFF; _Port_IOA_Buffer=0xFFFF; _Port_IOA_Data=0xFFFF; } 真正意义上能用的显示程序显示6789。 unsigned int * _Port_IOA_Attrib=0x7003, * _Port_IOA_Dir=0x7002, * _Port_IOA_Data=0x7000, * _Port_IOA_Buffer=0x7001, * ClearWatchdog = 0x7012; void IOA_Init() //IOA口初始化 { * _Port_IOA_Dir=0xFFFF; * _Port_IOA_Attrib=0xFFFF; //_Port_IOA_Buffer=0xFFFF; //_Port_IOA_Data=0xFFFF; } int main() { IOA_Init(); while(1) //程序结束循环 { /* _Port_IOA_Data=0x7000; * _Port_IOA_Buffer=0x7001; * _Port_IOA_Dir=0x7002; * _Port_IOA_Attrib=0x7003;*/ * _Port_IOA_Data=0xfe6f; * _Port_IOA_Data=0xfd7f; * _Port_IOA_Data=0xfb07; * _Port_IOA_Data=0xf77d; //[0~9]=[3f,06] //0x3f,0x06,0x5b,0x4f, // 0x66,0x6d,0x7d, // 0x07,0x7f,0x6f ClearWatchdog = 0x0001; //清看门狗 } } void F_Delay() { unsigned int i; for(i=0; i<500; i++) { } } 显示任意数字temp待改进 unsigned int * _Port_IOA_Attrib=0x7003, * _Port_IOA_Dir=0x7002, * _Port_IOA_Data=0x7000, * _Port_IOA_Buffer=0x7001, * ClearWatchdog = 0x7012; unsigned char code_table[]= { 0x3f,0x06,0x5b,0x4f, 0x66,0x6d,0x7d, 0x07,0x7f,0x6f }; void IOA_Init() //IOA口初始化 { * _Port_IOA_Dir=0xFFFF; * _Port_IOA_Attrib=0xFFFF; //_Port_IOA_Buffer=0xFFFF; //_Port_IOA_Data=0xFFFF; } int main() { IOA_Init(); while(1) //程序结束循环 { /* _Port_IOA_Data=0x7000; * _Port_IOA_Buffer=0x7001; * _Port_IOA_Dir=0x7002; * _Port_IOA_Attrib=0x7003;*/ unsigned int aa,dd,ge,shi,bai,temp; //bb=0x0002; temp=981; bai=temp/100; shi=temp%100; shi=shi/10; ge=temp%10; aa=0xfe00; dd=aa + code_table[ge]; * _Port_IOA_Data= dd; aa=0xfd00; dd=aa + code_table[shi]; * _Port_IOA_Data= dd; aa=0xfb00; dd=aa + code_table[bai]; * _Port_IOA_Data= dd; //* _Port_IOA_Data=0xfd7f; //* _Port_IOA_Data=0xfb07; //* _Port_IOA_Data=0xf77d; //[0~9]=[3f,06] //0x3f,0x06,0x5b,0x4f, // 0x66,0x6d,0x7d, // 0x07,0x7f,0x6f C语言的中断函数IRQ5 #include "hardware.h" unsigned int * _Port_IOA_Attrib=0x7008, ///////// * _Port_IOA_Dir=0x7007, /////////地址赋值 * _Port_IOA_Data=0x7005, ///////// * _Port_IOA_Buffer=0x7006, ///////// * ClearWatchdog = 0x7012, ///////// * P_INT_Ctrl=0x7010, ///////// * P_INT_Clear=0x7011, ///////// bb; int aa; void IOA_Init() /////////IOA口初始化 { * _Port_IOA_Dir=0xFFFF; * _Port_IOA_Attrib=0xFFFF; //_Port_IOA_Buffer=0xFFFF; //_Port_IOA_Data=0xFFFF; } int main() { IOA_Init(); __asm("IRQ ON"); //打开总中断 aa=0x0001; * P_INT_Ctrl=0x0008; //打开4Hz的中断 while(1) //程序结束循环 { * ClearWatchdog = 0x0001; //清看门狗 } } void IRQ5(void) __attribute__ ((ISR)); //中断专用格式 void IRQ5(void) //中断专用格式 { aa=aa+1; * _Port_IOA_Data= aa; * P_INT_Clear = 0x0008; //清中断 } void F_Delay() { unsigned int i; for(i=0; i<500; i++) { } } C语言的流水灯 #include "hardware.h" unsigned int * _Port_IOA_Attrib=0x7008, * _Port_IOA_Dir=0x7007, * _Port_IOA_Data=0x7005, * _Port_IOA_Buffer=0x7006, * ClearWatchdog = 0x7012, * P_INT_Ctrl=0x7010, * P_INT_Clear=0x7011, bb,aa; void IOA_Init() //IOA口初始化 { * _Port_IOA_Dir=0xFFFF; * _Port_IOA_Attrib=0xFFFF; //_Port_IOA_Buffer=0xFFFF; //_Port_IOA_Data=0xFFFF; } int main() { IOA_Init(); __asm("IRQ ON"); //INT_FIQ_IRQ(); aa=0x0001; * P_INT_Ctrl=0x0008; while(1) //程序结束循环 { * ClearWatchdog = 0x0001; //清看门狗 } } void IRQ5(void) __attribute__ ((ISR)); void IRQ5(void) { * ClearWatchdog = 0x0001; aa=aa<<1; //循环左移 //bb=aa; //bb=bb && 0x0100; while(aa==0x0100) aa=0x0001; bb=aa; //异或 取反 bb=bb^0xffff; * _Port_IOA_Data= bb; * P_INT_Clear = 0x0008; } C语言用timea做计数的流水灯 #include "hardware.h" unsigned int * _Port_IOA_Attrib=0x7008, * _Port_IOA_Dir=0x7007, * _Port_IOA_Data=0x7005, * _Port_IOA_Buffer=0x7006, * ClearWatchdog = 0x7012, * P_INT_Ctrl=0x7010, * P_INT_Clear=0x7011, * P_TimerA_Ctrl=0x700B, * P_TimerA_Data=0x700A, bb,aa; void IOA_Init() //IOA口初始化 { * _Port_IOA_Dir=0xFFFF; * _Port_IOA_Attrib=0xFFFF; //_Port_IOA_Buffer=0xFFFF; //_Port_IOA_Data=0xFFFF; } int main() { IOA_Init(); __asm("IRQ ON"); //INT_FIQ_IRQ(); aa=0x0001; * P_INT_Ctrl=0x1000; //设置中断 * P_TimerA_Ctrl=0x0034; * P_TimerA_Data=0xfe57;//设置计数初值 while(1) //程序结束循环 { * ClearWatchdog = 0x0001; //清看门狗 } } void IRQ1(void) __attribute__ ((ISR)); void IRQ1(void) { * ClearWatchdog = 0x0001; aa=aa<<1; //bb=aa; //bb=bb && 0x0100; while(aa==0x0100) aa=0x0001; bb=aa; bb=bb^0xffff; * _Port_IOA_Data= bb; * P_INT_Clear = 0x1000; } C语言的系统频率控制的流水灯 #include "hardware.h" unsigned int * _Port_IOA_Attrib=0x7008, * _Port_IOA_Dir=0x7007, * _Port_IOA_Data=0x7005, * _Port_IOA_Buffer=0x7006, * ClearWatchdog = 0x7012, * P_INT_Ctrl=0x7010, * P_INT_Clear=0x7011, * P_TimerA_Ctrl=0x700B, * P_TimerA_Data=0x700A, * P_SystemClock=0x7013, bb,aa; void IOA_Init() //IOA口初始化 { * _Port_IOA_Dir=0xFFFF; * _Port_IOA_Attrib=0xFFFF; //_Port_IOA_Buffer=0xFFFF; //_Port_IOA_Data=0xFFFF; } int main() { * P_SystemClock=0x0033; IOA_Init(); __asm("IRQ ON"); //INT_FIQ_IRQ(); aa=0x0001; * P_INT_Ctrl=0x1000; //设置中断 * P_TimerA_Ctrl=0x0031; * P_TimerA_Data=0x0000;//设置计数初值 while(1) //程序结束循环 { * ClearWatchdog = 0x0001; //清看门狗 } } void IRQ1(void) __attribute__ ((ISR)); void IRQ1(void) { * ClearWatchdog = 0x0001; aa=aa<<1; //bb=aa; //bb=bb && 0x0100; while(aa==0x0100) aa=0x0001; bb=aa; bb=bb^0xffff; * _Port_IOA_Data= bb; * P_INT_Clear = 0x1000; } #include "hardware.h" unsigned int * _Port_IOA_Attrib=0x7008, * _Port_IOA_Dir=0x7007, * _Port_IOA_Data=0x7005, * _Port_IOA_Buffer=0x7006, * ClearWatchdog = 0x7012, * P_INT_Ctrl=0x7010, * P_INT_Clear=0x7011, * P_TimerA_Ctrl=0x700B, * P_TimerA_Data=0x700A, * P_SystemClock=0x7013, * P_ADC_Ctrl=0x7015, * P_ADC_MUX_Ctrl=0x702b, * P_ADC_MUX_Date=0x702c, bb,aa; void IOA_Init() //IOA口初始化 { * _Port_IOA_Dir=0x0000; * _Port_IOA_Attrib=0xFFFF; //_Port_IOA_Buffer=0xFFFF; //_Port_IOA_Data=0xFFFF; } int main() { * P_ADC_Ctrl=0x0001; * P_ADC_MUX_Ctrl=0x0001; * P_SystemClock=0x0033; IOA_Init(); __asm("IRQ ON"); //INT_FIQ_IRQ(); aa=0x0001; * P_INT_Ctrl=0x1000; //设置中断 * P_TimerA_Ctrl=0x0031; * P_TimerA_Data=0x0f00;//设置计数初值 while(1) //程序结束循环 { * ClearWatchdog = 0x0001; //清看门狗 } } void IRQ1(void) __attribute__ ((ISR)); void IRQ1(void) { bb=* P_ADC_MUX_Date; while(P_ADC_MUX_Date=0x8000); * _Port_IOA_Data= bb; * P_INT_Clear = 0x1000; } C语言编的AD转换 //#include "hardware.h" unsigned int * _Port_IOB_Attrib=0x7008, * _Port_IOB_Dir=0x7007, * _Port_IOB_Data=0x7005, * _Port_IOB_Buffer=0x7006, * _Port_IOA_Attrib=0x7004, * _Port_IOA_Dir=0x7003, * _Port_IOA_Data=0x7000, * _Port_IOA_Buffer=0x7001, * ClearWatchdog = 0x7012, * P_INT_Ctrl=0x7010, * P_INT_Clear=0x7011, * P_TimerA_Ctrl=0x700B, * P_TimerA_Data=0x700A, * P_SystemClock=0x7013, * _P_ADC_Ctrl=0x7015, * _P_ADC_MUX_Ctrl=0x702b, * _P_ADC_MUX_Data=0x702c, bb,aa; int main() { * _Port_IOB_Attrib= 0xffff;//IOB口设置为同相输出口 * _Port_IOB_Dir=0xffff; * _Port_IOA_Attrib= 0xffff;//IOA口设置为xuanfushi 口 * _Port_IOA_Dir=0x0000; * _P_ADC_MUX_Ctrl=0x0001; //sheIOA0weiADshuru * _P_ADC_Ctrl=0x0001; //开启AD转换 while(1) { aa=* _P_ADC_MUX_Ctrl; aa=aa & 0x8000; while(aa!=0x8000); bb =* _P_ADC_MUX_Data; * _Port_IOB_Data=bb; * ClearWatchdog = 0x0001; //清看门狗 } } C语言编的数字电压表0~3.3V精确到0.001V unsigned int * _Port_IOB_Attrib=0x7008, * _Port_IOB_Dir=0x7007, * _Port_IOB_Data=0x7005, * _Port_IOB_Buffer=0x7006, * _Port_IOA_Attrib=0x7004, * _Port_IOA_Dir=0x7003, * _Port_IOA_Data=0x7000, * _Port_IOA_Buffer=0x7001, * _ClearWatchdog = 0x7012, * _P_INT_Ctrl=0x7010, * _P_INT_Clear=0x7011, * _P_TimerA_Ctrl=0x700B, * _P_TimerA_Data=0x700A, * _P_SystemClock=0x7013, * _P_ADC_Ctrl=0x7015, * _P_ADC_MUX_Ctrl=0x702b, * _P_ADC_MUX_Data=0x702c, bb,aa ,dd,ge,shi,bai,qian,temp; float qq; unsigned char code_table[]= { 0x3f,0x06,0x5b,0x4f, 0x66,0x6d,0x7d, 0x07,0x3f,0x6f }; void IOA_Init() //IOA口初始化 { * _Port_IOB_Dir=0xFFFF; * _Port_IOB_Attrib=0xFFFF; //_Port_IOA_Buffer=0xFFFF; //_Port_IOA_Data=0xFFFF; } int main() { __asm("IRQ ON"); * _P_INT_Ctrl=0x4000; IOA_Init(); * _Port_IOA_Attrib= 0xffff;//IOA口设置为xuanfushi 口 * _Port_IOA_Dir=0x0000; * _P_ADC_MUX_Ctrl=0x0001; //sheIOA0weiADshuru * _P_ADC_Ctrl=0x0001; //开启AD转换 while(1) //程序结束循 { aa=* _P_ADC_MUX_Ctrl; aa=aa & 0x8000; while(aa!=0x8000); temp=* _P_ADC_MUX_Data; qq=19.859090; temp=temp/qq; qian=temp/1000; bai=temp%1000/100; shi=temp%100/10; ge=temp%10; * _ClearWatchdog = 0x0001; //清看门狗 } } void IRQ0(void) __attribute__ ((ISR)); void IRQ0(void) { aa=0xfe00; dd=aa + code_table[ge]; * _Port_IOB_Data= dd; aa=0xfd00; dd=aa + code_table[shi]; * _Port_IOB_Data= dd; aa=0xfb00; dd=aa + code_table[bai]; * _Port_IOB_Data= dd; * _P_INT_Clear = 0x4000; aa=0xf700; dd=aa + code_table[qian]; * _Port_IOB_Data= dd; }