Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Atmega16 & 74ls922 problems

Status
Not open for further replies.

Mortalo

New Member
hi guys !!
hope youre doing ok.

im posting this, because im having a rather annoying problem.
what im trying to do is that with a 74ls922 and a keyboard with
4 rows and 3 columns i want to do an access control.

i need a password of 6 digits.
when i press * it erases all i have written to the lcd.
# its "ENTER" with that im reading the eeprom with the 6 digits.

thas the idea more or less, my issue is.

im testing my program on proteus, it works fine, but with my hardware.
im writing to the LCD to see that im getting the right numbers to see if im
on the right way, BUT when i press 1 2 3 it writes to the LCD with no problem
but when i press 4 5 6 it presents 1 2 3 respectively the same with 7 8 9 and with * 0 #. Its like its only writing to the lcd the values of the columns

for example 1 4 7 and * are on the same column, when i press any of this buttons it writes a "1" on the lcd. 2 5 8 0 are on the same column when i press any of this it writes a "2" on the lcd and so on.

im sensing the voltaje on PORTC that is where i enter the data ABCD from the 922 and its sending me the right voltaje, for example for "4"
pc0 = 0, pc1 = 0, pc2 = 1, pc3 = 0 (pc4-pc7 i have them grounded) but it keeps writing a "1" on the LCD.

pd2 i have it conected to data available of 922, and column 4 (X4) i have it
with no connection.

i was gessing that the portc may be damaged but i have 2 mega16 and im getting the same problem.

Can you give me any help ?
Im going to look for a priest, to exorcise this thing

this is my code
and my circuit on proteus is right here

Code:
#include <mega16.h>
#include <delay.h>
#include <stdio.h>

#define LCD_DATA PORTA
#define LCD_E    PORTD.6
#define LCD_RS   PORTD.4

unsigned char value;
unsigned char j,w;
unsigned char k =0;
 
 
 
void lcd_busy()
{
	delay_ms(5);
}

void lcd_wr_ir(unsigned char cmd)
{            
    LCD_E = 0;
	lcd_busy();
	LCD_RS = 0;		// data register	

    
	LCD_DATA = cmd; // MSN
	LCD_E = 1;
	LCD_E = 0;
	delay_us(200);
	
	LCD_DATA = cmd << 4; // LSN
	LCD_E = 1;
	LCD_E = 0;
	delay_us(200);
}

void lcd_wr_dr(unsigned char cmd)
{       
    LCD_E = 0;
	lcd_busy();
	LCD_RS = 1;		// data register	

    
	LCD_DATA = cmd; // MSN
	LCD_E = 1;
	LCD_E = 0;
	delay_us(200);
	
	LCD_DATA = cmd << 4; // LSN
	LCD_E = 1;
	LCD_E = 0;
	delay_us(200);
}

void lcd_int()
{   
	// to conect ports to  LCD
	DDRA = (DDRA & 0x0F)| 0xf0;	//  4 msb data port
	DDRD.4 = 1;					// Register select
	DDRD.6 = 1;                 // Enable LCD
//-------------------------------------------------------------------
	LCD_RS = 0;				
	LCD_DATA = 0x30;		
	LCD_E = 1;				
	LCD_E = 0;				
	delay_ms(5);
	
	LCD_DATA = 0x30;
	LCD_E = 1;
	LCD_E = 0;
	delay_ms(5);

	LCD_DATA = 0x30;
	LCD_E = 1;
	LCD_E = 0;
	delay_ms(5);

	LCD_DATA = 0x20;
	LCD_E = 1;
	LCD_E = 0;
	delay_ms(5);
//-----------------------------------------------------------------

	lcd_wr_ir(0b00101000);	//  4bits, 1 line, font 5x7
	lcd_wr_ir(0b00101000);	//  4bits, 1 line, font 5x7
	
	lcd_wr_ir(0b00101000);	//  4bits, 1 line, font 5x7
	lcd_wr_ir(0b00000110);  // lcd on, cursor on, blink on
	lcd_wr_ir(0b00001111);  // mov cur. /c escr., 
	lcd_wr_ir(0b00000001);  // cursor a home.
}
                    

#define _ALTERNATE_PUTCHAR_
void putchar(char c)
{
	lcd_wr_dr(c);
}                

void lcd_puts(flash unsigned char *s)
{
	while (*s != '\0')		// repeat till end 
		lcd_wr_dr(*s++);	// write data lcd change dir
}



interrupt [EXT_INT0] void exter()
{
	
 	PORTC = 0;
        value = 0;
        w++;
        if(w <= 1)
        {
       		lcd_int();  // to erase initially
        }
        
     	
	value = PINC; 
       	if(value == 0x0c)
 	{
     		k=0;
     		lcd_int();
     		value = 0x78;
     	 	w=0;
     		lcd_puts("enter PIN");    	
     	}
     	
     	
    	 
	value = PINC;
	

	
       	if(k <= 6)
	{
	switch(value)
	{  

 	  case 0x0d:
	  	lcd_puts("0");
	  	break;	
	  case 0x00:
	       lcd_puts("1");      
	       break;
       	  case 0x01:
	  	lcd_puts("2");
	  	break;
	  case 0x02:
	  	lcd_puts("3");
	     	break;
	  case 0x04:
	  	lcd_puts("4");
	  	break;
	  case 0x05:
	  	lcd_puts("5");
	  	break;
	  case 0x06:
	  	lcd_puts("6");
	  	break;
	  case 0x08:
	  	lcd_puts("7");
	  	break;
	  case 0x09:
	  	lcd_puts("8");
	  	break;
	  case 0x0a:
	  	lcd_puts("9");
	  	break;
	 // case 0x0c:
	 // 	lcd_puts("*");
	 // 	break;
	  case 0x0e:
	  	//lcd_puts("#");
	  	break; 			
	} 
	k++;
	value = 0;
	}
	      
                 

       
        
        










}

void main()
{	       

// 1 ====>>>> output
// 0 ====>>>> input

       
 // Declare your local variables here
PORTA=0x00;
DDRA=0xff;

PORTB=0x00;
DDRB=0x0b11000000;


PORTC=0x00;
DDRC=0x00;


PORTD=0x00;
DDRD=0b11111011;  


//external interrups  
 
	MCUCR = 0b00000011;   //into rising edge
	GICR  = 0x40;         //into enabled	
	SREG |= 0x80;         // ints enabled
	PORTD.1 = 0;		// Relay off
	PORTD.3 = 0;		// Led red on
	PORTD.5 = 1; 		// Led green off
	
// initialize LCD	
	delay_ms(50);
	lcd_int();
	
	lcd_puts("enter PIN");
	while(PINB == 0x00);
	
	
	
	
	
	
}
 

Attachments

  • try.JPG
    try.JPG
    177.1 KB · Views: 1,665
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top