AVR 1-99 seconds 1602 start and stop display

Publisher:WhisperingLightLatest update time:2015-06-23 Source: 51heiKeywords:AVR Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
#include
#include
#define uchar unsigned char
#define uint unsigned int
uint sec=0; //second variable
uint cnt=0; //count variable
uint on=0; //start/stop status variable
uchar str1[16]="The time: sec"; //All strings here have a certain length to eliminate display abnormalities caused by the pointer deviation of uncertain display codes
uchar start[16]=" start ";
uchar stop[16]=" stop ";
#include "1602.h"
void port_init()
{
  PORTA=0xff;
  DDRA=0xff;
  PORTB=0xff;
  DDRB=0xff;
  PORTD=0xff;
  DDRD=0xff;
}
void init()
{
  MCUCR=0x0a;
  GICR=0xc0;
  SREG=0x80;
}

void time0_init()
{
  TCCR0=0x03;
  TIMSK=0x01;
  TCNT0=0x83;
}
void showtime(uint time)
{
  displayonechar(10,0,(time/10)+48);
  displayonechar(11,0,(time%10)+48);
}

 
void main()
{
  
  port_init();
  //1602 device initialization
   delay(15);
writecmd(0x38);
delay(5);
writecmd(0x38);
delay(5);
writecmd(0x38);
writecmd(0x80);
writecmd(0x01);
writecmd(0x06);
writecmd(0x0c);
delay(500);
  //End of initialization

      init();
  time0_init();
  while(1)
  { 
   
   displaychar(0,0,str1);
   showtime(sec); //Display time value (seconds) Repeatedly overwrite these 2 digits to achieve the display effect
   delay(20);
  }
}

#pragma vector = 0x24 //Timer 0 overflow (timing seconds)
__interrupt void time0()
{
 TCNT0=0x83;
 if(on==1) //Start flag
 {
 cnt++;
 if(cnt==1000)
 {
   sec++;cnt=0;
 }
 if(sec>100)sec=0;
}
}
#pragma vector = 0x04 //INT0 interrupt service routine
__interrupt void int0()
{
  on=1;
 writecmd(0x01); // Clear screen
 displaychar(0,1,start); // Display start character
 displaychar(0,0,str1); // Display original character
   showtime(sec);
 
}
#pragma vector = 0x08 //INT1 interrupt service routine
__interrupt void int1()
{
  on=0;
  writecmd(0x01); //Clear screen
  displaychar(0,1,stop); //Display stop character
  displaychar(0,0,str1); //Display original character
   showtime(sec);
  
}
Keywords:AVR Reference address:AVR 1-99 seconds 1602 start and stop display

Previous article:The realization of automatic bell system for starting and ending classes based on AVR single chip microcomputer
Next article:AVR microcontroller PCF8591AD-DA experiment

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号