اطلاعیه

Collapse
No announcement yet.

مربع نشان دادن lcd کاراکتری 16*2

Collapse
X
 
  • فیلتر
  • زمان
  • Show
Clear All
new posts

    مربع نشان دادن lcd کاراکتری 16*2

    با عرض سلام. من یک مدار با میکروکنترلر mega8 درست کردم. مدار در پروتیوس به طور کامل و بی نقص کار می کنه. دفعه اولی که ای سی رو پروگرم کردم بدون ایراد کار می کرد و نوشته ها و پیغام ها رو روی lcd کاراکتری 16*2 درست نشون می داد. اما بعد از رفع ایرادات جزیی روی کد و پروگرام کردن مجدد lcd مربع نشون میده. واقعا کلافه کرده. اتصالات مدار رو تست کردم ایراد نداره. برای lcd هم پتانسیومتر گذاشتم. اومدم کد رو عوض کردم با کمال تعجب درست کار کرد! ولی کد اصلی کار نمی کنه. من احتمال میدم ایراد از کد باشه. کد رو میزارم بررسی کنید شاید رجیسترها ایراد داره. تشکر فراوان. خواهشا اگه میتونید حتما کمکم کنید خیلی برام مهمه.
    [FONT=Yekan]/*******************************************************[/FONT]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 : 2/9/2019
    Author :
    Company :
    Comments:




    Chip type : ATmega8
    Program type : Application
    AVR Core Clock frequency: 8.000000 MHz
    Memory model : Small
    External RAM size : 0
    Data Stack size : 256
    *******************************************************/


    #include <mega8.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <delay.h>
    // I2C Bus functions
    #include <i2c.h>


    // DS1307 Real Time Clock functions
    #include <ds1307.h>


    // Alphanumeric LCD functions
    #include <alcd.h>
    #define Delay 100
    // Declare your global variables here


    // External Interrupt 0 service routine
    unsigned char addhour(char);
    unsigned char addmin(char);
    int nextzang(unsigned char,unsigned char,unsigned char*,unsigned char*,int);
    void move_text(char*,char*);
    eeprom int nz;
    eeprom unsigned char hour_zang[16];
    eeprom unsigned char min_zang[16];


    interrupt [EXT_INT0] void ext_int0_isr(void)
    {

    unsigned char hh=0,mm=0,ss=0;
    unsigned char h1,m1;
    unsigned int i=1;
    unsigned int j=0;
    unsigned int numOfzang;
    unsigned char time[6];
    unsigned char str[16];
    bit change=0;

    PORTD.3=1;
    numOfzang=nz;
    delay_ms(10);


    i2c_init();
    rtc_init(0,0,0);
    lcd_init(16);
    rtc_get_time(&hh,&mm,&ss);
    h1=hh;
    m1=mm;
    while(1)
    {
    delay_ms(Delay);
    sprintf(str,"Set Time");
    lcd_clear();
    lcd_gotoxy(0,0);
    lcd_puts(str);
    sprintf(time,"%02u:%02u",h1,m1);
    lcd_gotoxy(0,1);
    lcd_puts(time);
    if(PIND.1==0)
    {
    h1=addhour(h1);
    change=1;
    delay_ms(Delay);
    }
    if(PIND.0==0)
    {
    m1=addmin(m1);
    change=1;
    delay_ms(Delay);
    }
    if(PIND.2==0){
    if(change==1)
    {
    rtc_set_time(h1,m1,'0');
    rtc_set_date(1,1,1,2019);
    delay_ms(20);
    }
    change=0;
    break;
    }
    }


    while(1)
    {
    delay_ms(Delay);
    sprintf(str,"Set Num of zang");
    lcd_clear();
    lcd_gotoxy(0,0);
    lcd_puts(str);
    lcd_gotoxy(0,1);
    sprintf(str,"%d",numOfzang);
    lcd_puts(str);
    if(PIND.1==0)
    {

    if(numOfzang<16){

    numOfzang=numOfzang+1;
    }
    else {
    numOfzang=1;
    }

    }


    if(PIND.2==0)
    {
    nz=numOfzang;
    delay_ms(10);
    break;
    }
    }

    while(1)
    {

    h1=hour_zang[j];
    delay_ms(10);
    m1=min_zang[j];
    delay_ms(10);
    if(i>numOfzang)
    break;
    while(1)
    {

    delay_ms(Delay);
    sprintf(str,"Set Zang %u",i);
    lcd_clear();
    lcd_gotoxy(0,0);
    lcd_puts(str);
    sprintf(time,"%02u:%02u",h1,m1);
    lcd_gotoxy(0,1);
    lcd_puts(time);
    if(PIND.1==0)
    {
    h1=addhour(h1);
    change=1;
    }
    if(PIND.0==0)
    {
    m1=addmin(m1);
    change=1;
    }
    if(PIND.2==0)
    {
    if(change==1)
    {
    hour_zang[j]=h1;
    delay_ms(10);
    min_zang[j]=m1;
    delay_ms(10);
    }
    change=0;
    break;
    }
    }
    j=j+1;
    i=i+1;

    }
    DDRC.2=1;
    PORTC.2=0;

    }


    void main(void)
    {
    // Declare your local variables here
    unsigned char h=0,m=0,s=0;
    unsigned char time[8],str1[8],str2[]="Designed By:Abolghasem Shahraki",str3[]="Tel:09151962664";
    unsigned char h_zang[8],m_zang[8];
    unsigned int nzang,i,near,tulzang=3;
    // Input/Output Ports initialization
    // Port B initialization
    // Function: Bit7=In Bit6=In Bit5=In Bit4=In Bit3=out Bit2=In Bit1=In Bit0=In
    DDRB=(0<<DDB7) | (0<<DDB6) | (0<<DDB5) | (0<<DDB4) | (1<<DDB3) | (0<<DDB2) | (0<<DDB1) | (0<<DDB0);
    // State: Bit7=T Bit6=T Bit5=T Bit4=T Bit3=T Bit2=T Bit1=T Bit0=T
    PORTB=(0<<PORTB7) | (0<<PORTB6) | (0<<PORTB5) | (0<<PORTB4) | (0<<PORTB3) | (0<<PORTB2) | (0<<PORTB1) | (0<<PORTB0);


    // Port C initialization
    // Function: Bit6=In Bit5=In Bit4=In Bit3=In Bit2=In Bit1=In Bit0=In
    DDRC=(0<<DDC6) | (0<<DDC5) | (0<<DDC4) | (0<<DDC3) | (0<<DDC2) | (0<<DDC1) | (0<<DDC0);
    // State: Bit6=T Bit5=T Bit4=T Bit3=T Bit2=T Bit1=T Bit0=T
    PORTC=(1<<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=out Bit2=In Bit1=In Bit0=In
    DDRD=(0<<DDD7) | (0<<DDD6) | (0<<DDD5) | (0<<DDD4) | (1<<DDD3) | (0<<DDD2) | (0<<DDD1) | (0<<DDD0);
    // State: Bit7=T Bit6=T Bit5=T Bit4=T Bit3=T Bit2=T Bit1=T Bit0=T
    PORTD=(0<<PORTD7) | (0<<PORTD6) | (0<<PORTD5) | (0<<PORTD4) | (0<<PORTD3) | (1<<PORTD2) | (1<<PORTD1) | (1<<PORTD0);


    // Timer/Counter 0 initialization
    // Clock source: System Clock
    // Clock value: Timer 0 Stopped
    TCCR0=(0<<CS02) | (0<<CS01) | (0<<CS00);
    TCNT0=0x00;


    // Timer/Counter 1 initialization
    // Clock source: System Clock
    // Clock value: Timer1 Stopped
    // Mode: Normal top=0xFFFF
    // OC1A output: Disconnected
    // OC1B output: Disconnected
    // Noise Canceler: Off
    // Input Capture on Falling Edge
    // Timer1 Overflow Interrupt: Off
    // Input Capture Interrupt: Off
    // Compare A Match Interrupt: Off
    // Compare B Match Interrupt: Off
    TCCR1A=(0<<COM1A1) | (0<<COM1A0) | (0<<COM1B1) | (0<<COM1B0) | (0<<WGM11) | (0<<WGM10);
    TCCR1B=(0<<ICNC1) | (0<<ICES1) | (0<<WGM13) | (0<<WGM12) | (0<<CS12) | (0<<CS11) | (0<<CS10);
    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: Timer2 Stopped
    // Mode: Normal top=0xFF
    // OC2 output: Disconnected
    ASSR=0<<AS2;
    TCCR2=(0<<PWM2) | (0<<COM21) | (0<<COM20) | (0<<CTC2) | (0<<CS22) | (0<<CS21) | (0<<CS20);
    TCNT2=0x00;
    OCR2=0x00;


    // Timer(s)/Counter(s) Interrupt(s) initialization
    TIMSK=(0<<OCIE2) | (0<<TOIE2) | (0<<TICIE1) | (0<<OCIE1A) | (0<<OCIE1B) | (0<<TOIE1) | (0<<TOIE0);


    // External Interrupt(s) initialization
    // INT0: On
    // INT0 Mode: Falling Edge
    // INT1: Off
    GICR|=(0<<INT1) | (1<<INT0);
    MCUCR=(0<<ISC11) | (0<<ISC10) | (1<<ISC01) | (0<<ISC00);
    GIFR=(0<<INTF1) | (1<<INTF0);


    // USART initialization
    // USART disabled
    UCSRB=(0<<RXCIE) | (0<<TXCIE) | (0<<UDRIE) | (0<<RXEN) | (0<<TXEN) | (0<<UCSZ2) | (0<<RXB8) | (0<<TXB8);


    // Analog Comparator initialization
    // Analog Comparator: Off
    // The Analog Comparator's positive input is
    // connected to the AIN0 pin
    // The Analog Comparator's negative input is
    // connected to the AIN1 pin
    ACSR=(1<<ACD) | (0<<ACBG) | (0<<ACO) | (0<<ACI) | (0<<ACIE) | (0<<ACIC) | (0<<ACIS1) | (0<<ACIS0);
    SFIOR=(0<<ACME);


    // ADC initialization
    // ADC disabled
    ADCSRA=(0<<ADEN) | (0<<ADSC) | (0<<ADFR) | (0<<ADIF) | (0<<ADIE) | (0<<ADPS2) | (0<<ADPS1) | (0<<ADPS0);


    // SPI initialization
    // SPI disabled
    SPCR=(0<<SPIE) | (0<<SPE) | (0<<DORD) | (0<<MSTR) | (0<<CPOL) | (0<<CPHA) | (0<<SPR1) | (0<<SPR0);


    // TWI initialization
    // TWI disabled
    TWCR=(0<<TWEA) | (0<<TWSTA) | (0<<TWSTO) | (0<<TWEN) | (0<<TWIE);


    // Bit-Banged I2C Bus initialization
    // I2C Port: PORTC
    // I2C SDA bit: 1
    // I2C SCL bit: 0
    // Bit Rate: 100 kHz
    // Note: I2C settings are specified in the
    // Project|Configure|C Compiler|Libraries|I2C menu.
    i2c_init();


    // DS1307 Real Time Clock initialization
    // Square wave output on pin SQW/OUT: Off
    // SQW/OUT pin state: 0
    rtc_init(0,0,0);


    // Alphanumeric LCD initialization
    // Connections are specified in the
    // Project|Configure|C Compiler|Libraries|Alphanumeric LCD menu:
    // RS - PORTB Bit 0
    // RD - PORTB Bit 1
    // EN - PORTB Bit 2
    // D4 - PORTB Bit 4
    // D5 - PORTB Bit 5
    // D6 - PORTB Bit 6
    // D7 - PORTB Bit 7
    // Characters/line: 16
    lcd_init(16);




    nzang=nz;
    delay_ms(10);
    for(i=0;i<nzang;i++)
    {
    h_zang[i]=hour_zang[i];
    delay_ms(15);
    m_zang[i]=min_zang[i];
    delay_ms(15);
    }
    PORTD.3=1;
    move_text(str2,str3);
    PORTD.3=0;
    rtc_get_time(&h,&m,&s);
    near=nextzang(h,m,h_zang,m_zang,nzang);


    //for(i=0;i<nzang;i++)
    //{
    // lcd_clear();
    // sprintf(str1,"%d %02u:%02u",near,h_zang[i],m_zang[i]);
    // lcd_puts(str1);
    // delay_ms(1000);
    //}




    // Global enable interrupts
    #asm("sei")


    while (1)
    {
    if (PIND.1==0)
    PORTD.3=1;
    else
    PORTD.3=0;

    if(h==h_zang[near] && m==m_zang[near])
    {
    PORTD.3=1;
    PORTB.3=1;
    near=nextzang(h,m,h_zang,m_zang,nzang);
    delay_ms(tulzang*1000);
    PORTB.3=0;
    PORTD.3=0;
    }

    rtc_get_time(&h,&m,&s);

    sprintf(time,"%02u:%02u:%02u",h,m,s);
    lcd_clear();
    lcd_gotoxy(0,0);
    lcd_puts(time);
    sprintf(str1,"next: %02u:%02u",h_zang[near],m_zang[near]);
    lcd_gotoxy(0,1);
    lcd_puts(str1);
    delay_ms(Delay);




    }
    }



    #2
    پاسخ : مربع نشان دادن lcd کاراکتری 16*2

    سلام.
    بعد خط 340 دستور lcd_clear(); استفاده کن ببین ال سی دی بازم این طوره.

    دیدگاه


      #3
      پاسخ : مربع نشان دادن lcd کاراکتری 16*2

      این کارو کردم حل نشد.

      دیدگاه

      لطفا صبر کنید...
      X