Hola que tal, de nuevo aqui, ahora con el mismo proyecto de un contador pero ahora en C, visible en un lcd 2*16 trabajando con el ATmega48, anteriormente lo habia practicado para asm con atmega32.
Bien el contador va funcionando bien solo tengo un pequeño detalle
, que no puedo visualizar las decenas ni centenas,unicamente cuando es el cambio, ojala alguien me pueda orientar.
(estoy trabajando con Codevisionavr compiler).
Tambien quice poner los delays de 40ms para compensar los flancos, y asi evitar un mal conteo.
En fin dejo el codigo aqui y un enlace en donde esta el circuito en proteus
http://cid-ab8ef72f672ad64b.skydrive.live.com/browse.aspx/.Public
Bien el contador va funcionando bien solo tengo un pequeño detalle
Tambien quice poner los delays de 40ms para compensar los flancos, y asi evitar un mal conteo.
En fin dejo el codigo aqui y un enlace en donde esta el circuito en proteus
http://cid-ab8ef72f672ad64b.skydrive.live.com/browse.aspx/.Public
PHP:
/*****************************************************
This program was produced by the
CodeWizardAVR V2.03.6 Evaluation
Automatic Program Generator
© Copyright 1998-2008 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com
Project : codevision_contador_m48_01
Version : 1.00
Date : 09/04/2010
Author : Freeware, for evaluation and non-commercial use only
Company :
Comments:
Chip type : ATmega48
Clock frequency : 1.000000 MHz
Memory model : Small
External RAM size : 0
Data Stack size : 128
*****************************************************/
#include <mega48.h>
#include <delay.h>
// Alphanumeric LCD Module functions
#asm
.equ __lcd_port=0x05 ;PORTB
#endasm
#include <lcd.h>
// Declare your global variables here
#define boton PINC.0
char var1;
char var2;
char var3;
//bit botonp;
//bit botona;
const unsigned char tablanumeros[10]={
0x30,
0x31,
0x32,
0x33,
0x34,
0x35,
0x36,
0x37,
0x38,
0x39,
};
void main(void)
{
// Declare your local variables here
// Crystal Oscillator division factor: 8
#pragma optsize-
CLKPR=0x80;
CLKPR=0x03;
#ifdef _OPTIMIZE_SIZE_
#pragma optsize+
#endif
// Input/Output Ports initialization
// Port B 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
PORTB=0x00;
DDRB=0x00;
// Port C initialization
// Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State6=P State5=P State4=P State3=P State2=P State1=P State0=P
PORTC=0x7F;
DDRC=0x00;
// 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;
// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
// Mode: Normal top=FFh
// OC0A output: Disconnected
// OC0B output: Disconnected
TCCR0A=0x00;
TCCR0B=0x00;
TCNT0=0x00;
OCR0A=0x00;
OCR0B=0x00;
// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: Timer 1 Stopped
// Mode: Normal top=FFFFh
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer 1 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
TCCR1A=0x00;
TCCR1B=0x00;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;
// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: Timer 2 Stopped
// Mode: Normal top=FFh
// OC2A output: Disconnected
// OC2B output: Disconnected
ASSR=0x00;
TCCR2A=0x00;
TCCR2B=0x00;
TCNT2=0x00;
OCR2A=0x00;
OCR2B=0x00;
// External Interrupt(s) initialization
// INT0: Off
// INT1: Off
// Interrupt on any change on pins PCINT0-7: Off
// Interrupt on any change on pins PCINT8-14: Off
// Interrupt on any change on pins PCINT16-23: Off
EICRA=0x00;
EIMSK=0x00;
PCICR=0x00;
// Timer/Counter 0 Interrupt(s) initialization
TIMSK0=0x00;
// Timer/Counter 1 Interrupt(s) initialization
TIMSK1=0x00;
// Timer/Counter 2 Interrupt(s) initialization
TIMSK2=0x00;
// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
ADCSRB=0x00;
// LCD module initialization
lcd_init(16);
while (1)
{
lcd_clear();
lcd_gotoxy(15,0);
lcd_putchar(tablanumeros[var1]);
delay_ms(100);
if (boton==0) //condicion se boton esta oprimido
//botona=0;
//else
//botonp=1;
//if((botonp==1)&&(botona==0)) // si hay cambio de flanco
{
//lcd_clear();
var1++; //incrementa la variable en uno
lcd_gotoxy(15,0);
lcd_putchar(tablanumeros[var1]); //pone en pantalla el numero
delay_ms(40); //tiempo para cambio de flanco
}
if (var1==10)
{
var1=0;
//lcd_clear();
lcd_putchar(tablanumeros[var2]);
var2++;
lcd_gotoxy(14,0);
lcd_putchar(tablanumeros[var2]);
delay_ms(400);
}
if (var2==10)
{
var2=0;
//lcd_clear();
lcd_putchar(tablanumeros[var3]);
var3++;
lcd_gotoxy(13,0);
lcd_putchar(tablanumeros[var3]);
delay_ms(500);
}
//if ((botonp==0)&&(botona==1)) //hubo cambio de flanco de 0 a 1
//delay_ms(40); //Se coloca retardo de 40mS para eliminar rebotes
//botonp=botona;
}
}