مهندسین من میخوام ال سی دی و کیپد راه اندازی کنم و از دو تا اینتراپت هم استفاده کنم. به این صورت که ما یکی از کلیدهای کی پد رو میزنیم مثلا شماره 15. بعد روی ال سی دی نمایش داده میشه. حالا با فعال کردن اینتراپت صفر یک عدد از 15 کم بشه و بشه 14 و با فعال کردن اینتراپت یک به عدد نمایش داده شده روی ال سی دی اضافه بشه. برنامه من مشکل داره. دوستان اگه کمکم کنید ممنون میشم.
[code=c]/************************************************** *****
This program was created by the
CodeWizardAVR V3.12 Advanced
Automatic Program Generator
© Copyright 1998-2014 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com
Project :
Version :
Date : 5/8/2016
Author :
Company :
Comments:
Chip type : ATmega16
Program type : Application
AVR Core Clock frequency: 1.000000 MHz
Memory model : Small
External RAM size : 0
Data Stack size : 256
************************************************** *****/
#include <mega16.h>
#include <stdio.h>
#include <delay.h>
#asm
.equ __lcd_port=0x18 ;PORTA
#endasm
// Alphanumeric LCD functions
#include <alcd.h>
#define c1 PINC.4
#define c2 PINC.5
#define c3 PINC.6
#define c4 PINC.7
// Declare your global variables here
int a;
// External Interrupt 0 service routine
interrupt [EXT_INT0] void ext_int0_isr(void)
{
a++;
}
// External Interrupt 1 service routine
interrupt [EXT_INT1] void ext_int1_isr(void)
{
a--;
}
unsigned char scan[4]={0XFE,0XFD,0XFB,0XF7};
unsigned char arrkey[16]={
9,10,11,12,
5,6,7,8,
1,2,3,4,
13,0,14,15};
char key;
unsigned char keypad()
{
unsigned char r,b;
while(1){
for (r=0; r<4; r++){
b=4;
PORTC=scan[r];
if(c1==0) b=0;
if(c2==0) b=1;
if(c3==0) b=2;
if(c4==0) b=3;
if (!(b==4)){
key=arrkey[(r*4)+b];
while(c1==0);
while(c2==0);
while(c3==0);
while(c4==0);
delay_ms(50);
return key;
}
}
}
}
void main(void)
{
char buffer[16];
lcd_init(16);
DDRC=0X0F;
PORTC=0XFF;
lcd_clear();
lcd_putsf("amir ferdowsi"
;
delay_ms(100);
while(1){
key=keypad();
lcd_clear();
sprintf(buffer,"%d",key);
lcd_puts(buffer);
delay_ms(100);
}
}
// Declare your local variables here
// Input/Output Ports initialization
// Port A initialization
// Function: Bit7=Out Bit6=Out Bit5=Out Bit4=Out Bit3=Out Bit2=Out Bit1=Out Bit0=Out
DDRA=(1<<DDA7) | (1<<DDA6) | (1<<DDA5) | (1<<DDA4) | (1<<DDA3) | (1<<DDA2) | (1<<DDA1) | (1<<DDA0);
// State: Bit7=0 Bit6=0 Bit5=0 Bit4=0 Bit3=0 Bit2=0 Bit1=0 Bit0=0
PORTA=(0<<PORTA7) | (0<<PORTA6) | (0<<PORTA5) | (0<<PORTA4) | (0<<PORTA3) | (0<<PORTA2) | (0<<PORTA1) | (0<<PORTA0);
// Port B initialization
// Function: Bit7=In Bit6=In Bit5=In Bit4=In Bit3=In Bit2=In Bit1=In Bit0=In
DDRB=(0<<DDB7) | (0<<DDB6) | (0<<DDB5) | (0<<DDB4) | (0<<DDB3) | (0<<DDB2) | (0<<DDB1) | (0<<DDB0);
// State: Bit7=P Bit6=P Bit5=P Bit4=P Bit3=P Bit2=P Bit1=P Bit0=P
PORTB=(1<<PORTB7) | (1<<PORTB6) | (1<<PORTB5) | (1<<PORTB4) | (1<<PORTB3) | (1<<PORTB2) | (1<<PORTB1) | (1<<PORTB0);
// Port C initialization
// Function: Bit7=In Bit6=In Bit5=In Bit4=In Bit3=In Bit2=In Bit1=In Bit0=In
DDRC=(0<<DDC7) | (0<<DDC6) | (0<<DDC5) | (0<<DDC4) | (0<<DDC3) | (0<<DDC2) | (0<<DDC1) | (0<<DDC0);
// State: Bit7=T Bit6=T Bit5=T Bit4=T Bit3=T Bit2=T Bit1=T Bit0=T
PORTC=(0<<PORTC7) | (0<<PORTC6) | (0<<PORTC5) | (0<<PORTC4) | (0<<PORTC3) | (0<<PORTC2) | (0<<PORTC1) | (0<<PORTC0);
// Port D initialization
// Function: Bit7=In Bit6=In Bit5=In Bit4=In Bit3=In Bit2=In Bit1=In Bit0=In
DDRD=(0<<DDD7) | (0<<DDD6) | (0<<DDD5) | (0<<DDD4) | (0<<DDD3) | (0<<DDD2) | (0<<DDD1) | (0<<DDD0);
// State: Bit7=P Bit6=P Bit5=P Bit4=P Bit3=P Bit2=P Bit1=P Bit0=P
PORTD=(1<<PORTD7) | (1<<PORTD6) | (1<<PORTD5) | (1<<PORTD4) | (1<<PORTD3) | (1<<PORTD2) | (1<<PORTD1) | (1<<PORTD0);
// External Interrupt(s) initialization
// INT0: On
// INT0 Mode: Rising Edge
// INT1: On
// INT1 Mode: Rising Edge
// INT2: Off
GICR|=(1<<INT1) | (1<<INT0) | (0<<INT2);
MCUCR=(1<<ISC11) | (1<<ISC10) | (1<<ISC01) | (1<<ISC00);
MCUCSR=(0<<ISC2);
GIFR=(1<<INTF1) | (1<<INTF0) | (0<<INTF2);
// Alphanumeric LCD initialization
// Connections are specified in the
// Project|Configure|C Compiler|Libraries|Alphanumeric LCD menu:
// RS - PORTA Bit 0
// RD - PORTA Bit 1
// EN - PORTA Bit 2
// D4 - PORTA Bit 4
// D5 - PORTA Bit 5
// D6 - PORTA Bit 6
// D7 - PORTA Bit 7
// Characters/line: 8
lcd_init(8);
// Global enable interrupts
#asm("sei"
while (1)
{
// Place your code here
key=keypad();
lcd_clear();
sprintf(buffer,"%d",key);
lcd_puts(buffer);
delay_ms(100);
}
}
[/code]
اضافه شده در تاریخ :
یه مسلمون نیست کمک کنه.مهندسییییین؟؟
اضافه شده در تاریخ :
مهندسین بلند شین از پشت میزاتون.به من کمک کنین
اضافه شده در تاریخ :
مهندسین کمک کنین.پلییییز
[code=c]/************************************************** *****
This program was created by the
CodeWizardAVR V3.12 Advanced
Automatic Program Generator
© Copyright 1998-2014 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com
Project :
Version :
Date : 5/8/2016
Author :
Company :
Comments:
Chip type : ATmega16
Program type : Application
AVR Core Clock frequency: 1.000000 MHz
Memory model : Small
External RAM size : 0
Data Stack size : 256
************************************************** *****/
#include <mega16.h>
#include <stdio.h>
#include <delay.h>
#asm
.equ __lcd_port=0x18 ;PORTA
#endasm
// Alphanumeric LCD functions
#include <alcd.h>
#define c1 PINC.4
#define c2 PINC.5
#define c3 PINC.6
#define c4 PINC.7
// Declare your global variables here
int a;
// External Interrupt 0 service routine
interrupt [EXT_INT0] void ext_int0_isr(void)
{
a++;
}
// External Interrupt 1 service routine
interrupt [EXT_INT1] void ext_int1_isr(void)
{
a--;
}
unsigned char scan[4]={0XFE,0XFD,0XFB,0XF7};
unsigned char arrkey[16]={
9,10,11,12,
5,6,7,8,
1,2,3,4,
13,0,14,15};
char key;
unsigned char keypad()
{
unsigned char r,b;
while(1){
for (r=0; r<4; r++){
b=4;
PORTC=scan[r];
if(c1==0) b=0;
if(c2==0) b=1;
if(c3==0) b=2;
if(c4==0) b=3;
if (!(b==4)){
key=arrkey[(r*4)+b];
while(c1==0);
while(c2==0);
while(c3==0);
while(c4==0);
delay_ms(50);
return key;
}
}
}
}
void main(void)
{
char buffer[16];
lcd_init(16);
DDRC=0X0F;
PORTC=0XFF;
lcd_clear();
lcd_putsf("amir ferdowsi"

delay_ms(100);
while(1){
key=keypad();
lcd_clear();
sprintf(buffer,"%d",key);
lcd_puts(buffer);
delay_ms(100);
}
}
// Declare your local variables here
// Input/Output Ports initialization
// Port A initialization
// Function: Bit7=Out Bit6=Out Bit5=Out Bit4=Out Bit3=Out Bit2=Out Bit1=Out Bit0=Out
DDRA=(1<<DDA7) | (1<<DDA6) | (1<<DDA5) | (1<<DDA4) | (1<<DDA3) | (1<<DDA2) | (1<<DDA1) | (1<<DDA0);
// State: Bit7=0 Bit6=0 Bit5=0 Bit4=0 Bit3=0 Bit2=0 Bit1=0 Bit0=0
PORTA=(0<<PORTA7) | (0<<PORTA6) | (0<<PORTA5) | (0<<PORTA4) | (0<<PORTA3) | (0<<PORTA2) | (0<<PORTA1) | (0<<PORTA0);
// Port B initialization
// Function: Bit7=In Bit6=In Bit5=In Bit4=In Bit3=In Bit2=In Bit1=In Bit0=In
DDRB=(0<<DDB7) | (0<<DDB6) | (0<<DDB5) | (0<<DDB4) | (0<<DDB3) | (0<<DDB2) | (0<<DDB1) | (0<<DDB0);
// State: Bit7=P Bit6=P Bit5=P Bit4=P Bit3=P Bit2=P Bit1=P Bit0=P
PORTB=(1<<PORTB7) | (1<<PORTB6) | (1<<PORTB5) | (1<<PORTB4) | (1<<PORTB3) | (1<<PORTB2) | (1<<PORTB1) | (1<<PORTB0);
// Port C initialization
// Function: Bit7=In Bit6=In Bit5=In Bit4=In Bit3=In Bit2=In Bit1=In Bit0=In
DDRC=(0<<DDC7) | (0<<DDC6) | (0<<DDC5) | (0<<DDC4) | (0<<DDC3) | (0<<DDC2) | (0<<DDC1) | (0<<DDC0);
// State: Bit7=T Bit6=T Bit5=T Bit4=T Bit3=T Bit2=T Bit1=T Bit0=T
PORTC=(0<<PORTC7) | (0<<PORTC6) | (0<<PORTC5) | (0<<PORTC4) | (0<<PORTC3) | (0<<PORTC2) | (0<<PORTC1) | (0<<PORTC0);
// Port D initialization
// Function: Bit7=In Bit6=In Bit5=In Bit4=In Bit3=In Bit2=In Bit1=In Bit0=In
DDRD=(0<<DDD7) | (0<<DDD6) | (0<<DDD5) | (0<<DDD4) | (0<<DDD3) | (0<<DDD2) | (0<<DDD1) | (0<<DDD0);
// State: Bit7=P Bit6=P Bit5=P Bit4=P Bit3=P Bit2=P Bit1=P Bit0=P
PORTD=(1<<PORTD7) | (1<<PORTD6) | (1<<PORTD5) | (1<<PORTD4) | (1<<PORTD3) | (1<<PORTD2) | (1<<PORTD1) | (1<<PORTD0);
// External Interrupt(s) initialization
// INT0: On
// INT0 Mode: Rising Edge
// INT1: On
// INT1 Mode: Rising Edge
// INT2: Off
GICR|=(1<<INT1) | (1<<INT0) | (0<<INT2);
MCUCR=(1<<ISC11) | (1<<ISC10) | (1<<ISC01) | (1<<ISC00);
MCUCSR=(0<<ISC2);
GIFR=(1<<INTF1) | (1<<INTF0) | (0<<INTF2);
// Alphanumeric LCD initialization
// Connections are specified in the
// Project|Configure|C Compiler|Libraries|Alphanumeric LCD menu:
// RS - PORTA Bit 0
// RD - PORTA Bit 1
// EN - PORTA Bit 2
// D4 - PORTA Bit 4
// D5 - PORTA Bit 5
// D6 - PORTA Bit 6
// D7 - PORTA Bit 7
// Characters/line: 8
lcd_init(8);
// Global enable interrupts
#asm("sei"

while (1)
{
// Place your code here
key=keypad();
lcd_clear();
sprintf(buffer,"%d",key);
lcd_puts(buffer);
delay_ms(100);
}
}
[/code]
اضافه شده در تاریخ :
یه مسلمون نیست کمک کنه.مهندسییییین؟؟
اضافه شده در تاریخ :
مهندسین بلند شین از پشت میزاتون.به من کمک کنین
اضافه شده در تاریخ :
مهندسین کمک کنین.پلییییز
دیدگاه