thomgun_lc said:Does any one have example source code in c programming to program AVR ic?So, we can analyze the program together.
This topic is useless, it's about compilers for ARM MCUs and not AVR MCUs!Moof said:For those who didnt chose the compiler, check this
#include "iom32.h"
const unsigned char num[10]={0X3F,0X24,0X5D,0X75,0X66,0X73,0X7B,0X25,0X7F,0X77};
char i=0;
void delay(unsigned long int delayValue)
{
unsigned long int a;
for(a=0;a<delayValue;a++) ;
}
main()
{
DDRB=0xff;//PORTB as output
for(;;)
{
if(i<=9)//分别显示0-9
{
PORTB=num[i];
delay(662767);
i++;
}
else
{
i=0;
}
}
}
.include "m32def.inc"
.def mp=r16;
.def tm=r17;timer 1
.def tm2=r18;timer2
.def tm3=r21;timer3
.def shu=r19;loop counter
.def max=r20;max of loop
;.def num=r21
;----ldi number---
ldi tm3,250
ldi max,23
;ldi num,2
;----dingyi0----
ldi mp,0xff
out ddrb,mp
out ddrd,mp
out ddrc,mp;aaa
out portc,mp;aaa
;======stack=======
ldi mp,high(ramend)
out sph,mp
ldi mp,low(ramend)
out spl,mp
;=================
ldi mp,0x80;aaa
out mcucsr,mp;aaa
main:
ldi mp,0X3F;0显示first0
out portb,mp
ldi mp,0xfe
out portd,mp
nop
;clz
rcall delay1
ldi mp,0X24;1display 1
out portb,mp
ldi mp,0xfd
out portd,mp
nop
;clz
rcall delay1
ldi mp,0X5D;2display 2
out portb,mp
ldi mp,0xfb
out portd,mp
nop
;clz
rcall delay1
ldi mp,0X75;3display 3
out portb,mp
ldi mp,0xf7
out portd,mp
nop
;clz
rcall delay1
ldi mp,0X66;4display 4
out portb,mp
ldi mp,0xef
out portd,mp
nop
;clz
rcall delay1
ldi mp,0X73;5display 5
out portb,mp
ldi mp,0xdf
out portd,mp
nop
;clz
rcall delay1
ldi mp,0X7B;65display
out portb,mp
ldi mp,0xbf
out portd,mp
nop
;clz
rcall delay1
ldi mp,0X25;7display
out portb,mp
ldi mp,0x7f
out portd,mp
nop
;clz
rcall delay1
rjmp main
delay1:;delay 1ms
inc tm
breq jmm1
rjmp delay1
jmm1:
clz
ret
.include "m32def.inc"
.def mp=r16
.def tm=r17
.def tm2=r18
.def shu=r19
.def max=r20
.def tm3=r21
ldi tm3,250
ldi max,23
ldi mp,0xff
out ddrb,mp
ldi mp,high(ramend)
out sph,mp
ldi mp,low(ramend)
out spl,mp
main:
ldi zh,high(mytable<<1)
ldi zl,low(mytable<<1)
ldi shu,0
loop:
cpse shu,max
rjmp dis
rjmp main
dis:
;add zl,shu
lpm
mov mp,r0
out portb,mp
rcall delay10
inc shu
adiw zl,2
rjmp loop
Delay10:
inc tm
brne delay10
inc tm2
brne delay10
inc tm3
breq jmm
rjmp delay10
jmm:
clz
ldi tm3,250
RET
;.eseg
mytable:
.dw 0XCF;0
.dw 0X03;1
.dw 0X5D;2
.dw 0X5B;3
.dw 0X93;4
.dw 0XDA;5
.dw 0XDE;6
.dw 0X43;7
.dw 0XDF;8
.dw 0XDB;9
.dw 0XD7;A
.dw 0X9E;b
.dw 0XCC;C
.dw 0X1C;c
.dw 0X1F;d
.dw 0XDC;E
.dw 0XD4;F
.dw 0X97;H
.dw 0X96;h
.dw 0X8C;L
.dw 0XD5;P
.dw 0X9C;t
.dw 0X10;-
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?