Since two different types of mouths were built in this tutorial, two different types of software were written, each unique to the design.
First: I'll show is what additions were made to the animatronic mouth's code (see eyebrows/eyes for previous code).
Second: the core parts of the main function for the LCD Mouth is shown to convey its simplicity.
Timer0 Interrupt Routine
------------« Begin Code »------------
... .... else if(PIR1bits.TMR1IF == 1) { //If Timer1 interrupts, do your thing... count++; //Increment Timer1 Interrupt Counter switch(count){ //Choose which servo to modify case 1: PORTD = 0x01; WriteTimer1( servo0 ); //Right Eyebrow break; case 2: PORTD = 0x02; WriteTimer1( servo1 ); //Left Eyebrow break; case 3: PORTD = 0x04; WriteTimer1( servo2 ); //Left Eye Left/Right break; case 4: PORTD = 0x08; WriteTimer1( servo3 ); //Left Eye Up/Down break; case 5: PORTD = 0x10; WriteTimer1( servo4 ); //Right Eye Left/Right break; case 6: PORTD = 0x20; WriteTimer1( servo5 ); //Right Eye Up/Down break; case 7: PORTD = 0x40; WriteTimer1( servo6 ); //Mouth break; case 8: PORTD = 0x00; WriteTimer1( 0 ); break; } PIR1bits.TMR1IF = 0; //Clear Timer1 flag } .... ...
------------« End Code »------------
As you can see above the new addition to this software is for servo6. This is the servo that will control the mouth's movement. It will be more typical to write directly to the servo control for fast movements, since mouths tend to move very fast, compared to the eyebrows or eyes which more often require slower and gradual movements.
LCD Mouth Main Function Overview
------------« Begin Code »------------
... .... while(1){ //Don't PORTA = 0x00; // Backlight On Delay1KTCYx(20*10); PORTA = 0x01; // Backlight Off Delay1KTCYx(20*10); //Be PORTA = 0x00; // Backlight On Delay1KTCYx(20*10); PORTA = 0x01; // Backlight Off Delay1KTCYx(20*10); //Fooled PORTA = 0x00; // Backlight On Delay1KTCYx(20*14); PORTA = 0x01; // Backlight Off Delay1KTCYx(20*30); .... ...
------------« End Code »------------
The software above is primarily PORTA controlling the backlight for specific times to 'speak' specific words. The PIC delay functions were used to get exact timing between spoken words matched up with lighting the LCD. This is crucial if we want to properly create the illusion of a speaking robot or animatron.