📄 m128_my.c
字号:
//ICC-AVR application builder : 2007-2-21 下午 09:30:23
// Target : M128
// Crystal: 8.0000Mhz
#include <iom128v.h>
#include <macros.h>
int v=0;
unsigned int time=0;
void port_init(void)
{
}
//ADC initialize
// Conversion time: 3uS
void adc_init(void)
{
ADCSRA = 0x00; //disable adc
ADMUX = 0x00; //select adc input 0
ACSR = 0x80;
ADCSRA = 0xE9;
}
#pragma interrupt_handler adc_isr:22
void adc_isr(void)
{
//conversion complete, read value (int) using...
v=ADCL; //Read 8 low bits first (important)
v|=(int)ADCH << 8; //read 2 high bits and shift into top byte
}
//call this routine to initialize all peripherals
void init_devices(void)
{
//stop errant interrupts until set up
CLI(); //disable all interrupts
XDIV = 0x00; //xtal divider
XMCRA = 0x00; //external memory
port_init();
adc_init();
timer0_init();
MCUCR = 0x00;
EICRA = 0x0A; //extended ext ints
EICRB = 0x00; //extended ext ints
EIMSK = 0x03;
TIMSK = 0x01; //timer interrupt sources
ETIMSK = 0x00; //extended timer interrupt sources
SEI(); //re-enable interrupts
//all peripherals are now initialized
}
//TIMER0 initialize - prescale:64
// WGM: Normal
// desired value: 1mSec
// actual value: 1.000mSec (0.0%)
void timer0_init(void)
{
TCCR0 = 0x00; //stop
ASSR = 0x00; //set async mode
TCNT0 = 0x83; //set count
OCR0 = 0x7D;
TCCR0 = 0x04; //start timer
}
#pragma interrupt_handler timer0_ovf_isr:17
void timer0_ovf_isr(void)
{
TCNT0 = 0x83; //reload counter value
time++;
}
#pragma interrupt_handler int0_isr:2
void int0_isr(void)
{
//external interupt on INT0
EIMSK = 0x00;
PORTB=0xfe;
}
#pragma interrupt_handler int1_isr:3
void int1_isr(void)
{
//external interupt on INT1
EIMSK = 0x00;
PORTB=0xfd;
}
/* 传送ASCII字母到LCD */
/* x:0x00~0x0f y:0~64 */
void asc_tran1(unsigned char x,unsigned char y,unsigned char *asc_p)
{
x+=4;
//while((*asc_p)!=0)
{
ocmj_write(0xf1);
ocmj_write(x);
ocmj_write(y);
ocmj_write(*asc_p);
asc_p++;
if (x<0x13)
x++;
else
{
x=0x04;
y+=8;
}
}
}
main()
{
int x=0,a=0,i=0;
char j=0;
char code[]={'0','1','2','3','4','5','6','7','8','9','-','+',};
DDRD=0x00;
PORTD=0x03;
//while(1);
init_devices();
ocmj_init();//初始化
ocmj_write(0xf4);//清屏
hz_tran(3,0,"数模转换");//传送内部汉字
DDRB=0x03;
PORTB=0xfc;
//while(1);
while(1)
{ for(j=0;j<128;j++)
{ x=v;
pset(j,x/17);
for(i=0;i<7;i++)
{
if (x<0)
{x=-x;asc_tran1(9-7,50,& code[10]);}
a=x%10;
asc_tran1(10-i,50,& code[a]);
x=x/10;
} //for
delay_ms(1);
if (time>100)
{ EIMSK = 0x03;
PORTB=0xfc;
}
//asm("cbi 0x03,0");
//asm("cbi 0x03,1");
}//for
ocmj_write(0xf4);//清屏
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -