Question: I Have a code in C for a cronometer in display with an arduino nano to a lcd screen, how can I add an animation

I Have a code in C for a cronometer in display with an arduino nano to a lcd screen,

how can I add an animation with special characters that when the stopwatch is running it moves and remains still when it is "stop". The stopwatch in its time counting function should not be affected by adding the animation.

here is the code:

#asm .equ __lcd_port=0x05 .equ __lcd_EN=1 .equ __lcd_RS=0 .equ __lcd_D4=2 .equ __lcd_D5=3 .equ __lcd_D6=4 .equ __lcd_D7=5 #endasm

#include #include #include #include

unsigned char M=0, S=0, D=0; char Cadena[17];

void main(void) {

SetupLCD(); PORTD.0=1; PORTD.1=1;

while (1) { sprintf(Cadena, "%02i:%02i.%i",M,S,D); MoveCursor(4,0); StringLCDVar(Cadena); delay_ms(62); delay_us(350); if(PIND.0==0) D++; if (D==10) { D=0; S++; if (S==60) { S=0; M++; if (M==60) M=0;

} }

if (PIND.1==0) { M=0; S=0; D=0; }

} }

here is the library "display.h" that is used

//Library for using a LCD by Agustin Dominguez Version3 // Copy this file to "inc" folder and put LCD connections before the #include //If the LCDs connections change, you need to change the #define below and SetupLCD for defining the necessary outputs // For example // #asm // .equ __lcd_port=0x0C // .equ __lcd_EN=1 // .equ __lcd_RS=0 // .equ __lcd_D4=2 // .equ __lcd_D5=3 // .equ __lcd_D6=4 // .equ __lcd_D7=5 // #endasm // #include

//You need to copy this library to the inc folder

#include unsigned char cursor;

#pragma used+

void SendDataBitsLCD(unsigned char dato); void WriteComandLCD(unsigned char Comando); void PulseEn();

/* Procedimiento para configurar el LCD. Es necesaria ejecutar al inicio para el correcto funcionamiento */ /* en un LCD fsico (no es crtico para simulcacin slo en Proteus*/ void SetupLCD() { unsigned char TableSetup[12]={3,3,3,2,2,12,0,8,0,1,0,6}; unsigned char i; #asm SBI __lcd_port-1,__lcd_EN SBI __lcd_port-1,__lcd_RS SBI __lcd_port-1,__lcd_D4 SBI __lcd_port-1,__lcd_D5 SBI __lcd_port-1,__lcd_D6 SBI __lcd_port-1,__lcd_D7 #endasm //DDRF=DDRF|0x3F; //Outputs for LCD delay_ms(50); for (i=0;i<12;i++) { delay_ms(2); SendDataBitsLCD(TableSetup[i]); PulseEn(); } cursor=0x0C; //Display ON, invisible cursor WriteComandLCD(cursor); } void PulseEn() { #asm SBI __lcd_port,__lcd_EN // EN=1; CBI __lcd_port,__lcd_EN // EN=0; #endasm }

void SendDataBitsLCD(unsigned char dato) { if ((dato&0x08)!=0) #asm("SBI __lcd_port,__lcd_D7") //D7=1; else #asm("CBI __lcd_port,__lcd_D7") // D7=0; if ((dato&0x04)!=0) #asm("SBI __lcd_port,__lcd_D6") // D6=1; else #asm("CBI __lcd_port,__lcd_D6") // D6=0; if ((dato&0x02)!=0) #asm("SBI __lcd_port,__lcd_D5") else #asm("CBI __lcd_port,__lcd_D5") // D5=0; if ((dato&0x01)!=0) #asm("SBI __lcd_port,__lcd_D4") //D4=1; else #asm("CBI __lcd_port,__lcd_D4") //D4=0; }

void WriteComandLCD(unsigned char Comando) { unsigned char tempComando; #asm("CBI __lcd_port,__lcd_RS") //RS=0; delay_ms(2); tempComando=Comando&0xF0; tempComando=tempComando>>4; SendDataBitsLCD(tempComando); PulseEn(); tempComando=Comando&0x0F; SendDataBitsLCD(tempComando); delay_ms(2); PulseEn(); }

/* Sends a character to LCD where the cursor is located*/ void CharLCD(unsigned char dato) { unsigned char tempdato; #asm("SBI __lcd_port,__lcd_RS") // RS=1; delay_ms(2); tempdato=dato&0xF0; tempdato=tempdato>>4; SendDataBitsLCD(tempdato); PulseEn(); tempdato=dato&0x0F; SendDataBitsLCD(tempdato); delay_ms(2); PulseEn(); }

/* Sends a fixed string to LCD*/ void StringLCD(flash unsigned char Mensaje[]) { unsigned char i; i=0; do{ CharLCD(Mensaje[i++]); }while(Mensaje[i]!=0); }

/* Sends a fixed string to LCD with delay (msec) among each character*/ void StringLCD2(flash unsigned char Mensaje[],unsigned int tiempo) { unsigned char i; i=0; do{ CharLCD(Mensaje[i++]); delay_ms(tiempo); }while(Mensaje[i]!=0); }

/* Sents a varible string to LCD*/ void StringLCDVar(unsigned char Mensaje[]) { unsigned char i; i=0; do{ CharLCD(Mensaje[i++]); }while(Mensaje[i]!=0); }

/* Erase all LCD */ void EraseLCD( ) { WriteComandLCD(1); }

/* Move coursor to the position (x,y) */ /* x: Column number 0 a 15 */ /* y: Row number 0 or 1 */ void MoveCursor(unsigned char x, unsigned char y) { switch (y) { case(0): WriteComandLCD(0x80+x); break; case(1): WriteComandLCD(0xC0+x); break; case(2): WriteComandLCD(0x94+x); break; case(3): WriteComandLCD(0xD4+x); break; } }

/* It appers the Underscore Cursor _ */ void UnderscoreCursor() { cursor=cursor|0x02; WriteComandLCD(cursor); }

/* It disappers the Underscore Cursor*/ void NoUnderscoreCursor() { cursor=cursor&0xFD; WriteComandLCD(cursor); }

/* It appers the Blink cursor */ void BlinkCursor() { cursor=cursor|0x01; WriteComandLCD(cursor); }

/* It disappears the Blink cursor */ void NoBlinkCursor() { cursor=cursor&0xFE; WriteComandLCD(cursor); }

/* Crate a custum character Parameters: NoCaracter.- number from 0 to 7 (you can have 8 custum characters) datos[8].- Array with 8 bytes with the draw of the custum character, a 1 stands for a black pixel. 0x00 $ $ 0x0A $ $ $ 0x15 $ $ 0x11 $ $ 0x0A $ 0x04 Example: unsigned char Letra0[8] = {0x00, 0x0A, 0x15, 0x11, 0x0A, 0x04}; //Caracter como un corazn CreateChar(0, Letra0); For display this character use: CharLCD(0); */

void CreateChar(unsigned char NoCaracter, unsigned char datos[8]) { unsigned char i; WriteComandLCD(0x40+NoCaracter*8); for (i=0;i<8;i++) CharLCD(datos[i]); WriteComandLCD(0x80); }

#pragma used-

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!