BASIC4MCU | 질문게시판 | LCD 7segment switch 인터럽트함수 변수제어
페이지 정보
작성자 시속90 작성일2022-10-21 23:24 조회2,198회 댓글0건본문
1. 스위치를 이용해 PIND0 스위치는 일의 자리 수 증가, PIND1 스위치는 십의 자리 수 증가
2. 7세그멘트를 이용해 숫자 표시
3. LCD를 이용해 숫자 표시
의도로 짠 코드입니다. 질문은 LCD 제어를 위해 인터럽트 함수 안에 변수를 집어넣어야 하는데
전역변수 사용하는 방법은 생각나지만 어떻게 사용하는지 모르겠습니다. 현재 코드로는 too many arguments 'write_data'가 뜹니다
이 방법 외에도 다른 방법이 있을까요?
#include <iom128v.h>
#include <avrdef.h>
void delay_ms(unsigned int m){
unsigned int i,j;
for(i=0;i<m;i++){
for(j=0;j<2000;j++);
}
}
void delay_us(unsigned int u){
unsigned int i,j;
for(i=0;i<u;i++){
for(j=0;j<2;j++);
}
}
unsigned char FND_DATA_TBL []={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7C,0x07,0x7F,0x67};
void delay_ms(unsigned int m);
void delay_us(unsigned int u);
void write_data(char d);
void write_instruction(char i);
void init_lcd(void);
void int0_isr();
char X;
char Y;
int main(void)
{
DDRA = 0x0f; DDRC = 0xff; DDRB = 0x07;
DDRE = 0xff; DDRF = 0xff; DDRD = 0x00;
EICRA = 0xA;
EIMSK = 0x07;
char x=0;
char y=0;
SEI();
while(1){
PORTE = FND_DATA_TBL[x];
PORTF = FND_DATA_TBL[y];
if((PIND&0x01)==0x01){ //PIND&0x01!=0x01
x++;
}
if((PIND&0x02)==0x02){ //PIND&0x02!=0x02
y++;
}
if(x>=10){
x=0;
y++;
}
if(y>=10)
y=0;
delay_ms(300);
}
return 0;
}
#pragma interrupt_handler int0_isr:iv_INT0
void int0_isr(){
init_lcd();
write_instruction(0x80);
write_data('1');
write_instruction(0x81);
write_data('0');
write_instruction(0x82);
write_data(':');
write_instruction(0x83);
write_data('%c',Y);
write_instruction(0xc0);
write_data('0');
write_instruction(0xc1);
write_data('1');
write_instruction(0xc2);
write_data(':');
write_instruction(0xc3);
write_data('%c',X);
}
void init_lcd(void){
delay_ms(10);
write_instruction(0x30);
delay_ms(25);
write_instruction(0x30);
delay_ms(5);
write_instruction(0x30);
delay_ms(5);
write_instruction(0x3c);
delay_ms(5);
write_instruction(0x08);
delay_ms(5);
write_instruction(0x01);
delay_ms(5);
write_instruction(0x06);
delay_ms(5);
write_instruction(0x0C);
delay_ms(15);
}
void write_instruction(char i){
PORTB=0x04;
delay_us(10);
PORTC=i;
delay_us(10);
PORTB=0x00;
delay_us(100);
}
void write_data(char d){
PORTB=0x05;
delay_us(10);
PORTC=d;
delay_us(10);
PORTB=0x01;
delay_us(100);
}
감사합니다.
댓글 0
조회수 2,198등록된 댓글이 없습니다.