|
发表于 2011-6-22 11:01:42
|
显示全部楼层
回复【81楼】pjs9115916
-----------------------------------------------------------------------
#include <mega16.h>
#include <delay.h>
#define uchar unsigned char
#define uint unsigned int
flash char dis_str[]="interrupt into test!";
// Alphanumeric LCD Module functions
#asm
.equ __lcd_port=0x15 ;PORTC
#endasm
#include <lcd.h>
uchar counter;
// External Interrupt 0 service routine
interrupt [EXT_INT0] void ext_int0_isr(void)
{
// Place your code here
if(++counter>=16)counter=0;
}
// External Interrupt 1 service routine
interrupt [EXT_INT1] void ext_int1_isr(void)
{
// Place your code here
if(counter)counter--;
else counter=15;
}
// Declare your global variables here
/* function used to define user characters
void define_char(byte flash *pc,byte char_code)
{
byte i,a;
a=(char_code<<3) | 0x40;
for (i=0; i<8; i++) lcd_write_byte(a++,*pc++);
} */
void main(void)
{
char flash *str;
str=dis_str;
// Port D initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTD=0x00;
DDRD=0x00;
// External Interrupt(s) initialization
// INT0: On
// INT0 Mode: Falling Edge
// INT1: On
// INT1 Mode: Falling Edge
// INT2: Off
GICR|=0xC0;
MCUCR=0x0A;
MCUCSR=0x00;
GIFR=0xC0;
// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
SFIOR=0x00;
// LCD module initialization
lcd_init(16);
//define_char(counter,0);
// Global enable interrupts
#asm("sei")
while (1)
{ //lcd_write_byte(0,counter);
// Place your code here
lcd_clear();
//lcd_putsf("data show:");
lcd_putchar(counter); //这里要怎么写啊 把那个counter里的数字显示到1602上面
delay_ms(100) ;
lcd_gotoxy(0,1);
lcd_putsf(str) ;
if(*str++==0)str=dis_str;
delay_ms(500) ;
};
}
lcd_putchar(counter); //这里要怎么写啊 把那个counter里的数字显示到1602上面 |
|