Appendix 2:  Video Code

 

//Gustavo Bitdinger - gbb7

//Rangarajan Rajagopalan - rr234

//ECE 476 Final Project - Weatherdog

//Mon. May 2, 2005

 

#pragma regalloc-    //I allocate the registers myself

#pragma optsize-     //optimize for speed    

                    

#include <Mega32.h>  

#include <stdio.h>

#include <stdlib.h>

#include <math.h>

#include <delay.h> 

 

#include <string.h>

 

//cycles = 63.625 * 16 Note NTSC is 63.55

//but this line duration makes each frame exactly 1/60 sec

//which is nice for keeping a realtime clock

#define lineTime 1018

 

#define begin {

#define end   }

 

//screen line definitions

#define ScreenTop 30

#define ScreenBot 230

#define width           126

#define length          99

#define inner_top       11

#define inner_bottom 76  

 

//NOTE that v1 to v8 and i must be in registers! 

register char v1 @4;

register char v2 @5;

register char v3 @6;

register char v4 @7;

register char v5 @8;

register char v6 @9;

register char v7 @10;

register char v8 @11;

register int i @12;

register int j @13;

 

#define LCDwidth 16

 

//define some states

#define PLAY  0

#define WAIT1 1

#define WAIT2 2

 

#pragma regalloc+

 

//video synchronizationvariables

char syncON, syncOFF;

int LineCount;

 

unsigned char keyboard_input;  //input from EITHER keyboard or PC

                                     

char screen[1600], t, ts[10], temp_string[2]; 

 

//some strings to print to the TV

char program_string[] = "WEATHERDOG";

char copyright_string[] = "C.2005";

char input_string[] = "SEARCH@ICAO@CODE:@";

char result_temperature[] = "TEMP@DEG@F@@@";

char result_humidity[] = "HUMID@PERCENT";

char result_wind[] = "WIND MPH@@@@@";

char result_visibility[] = "VISIBILITY@MI";

char blankStr[] = "         ";

char blankStr1[] = "           ";

char blankStr2[] = " ";

char small_blankStr[] = "@@@@@@@@@";                

char searching[] = "SEARCHING";

 

int index;  //index of where cursor for input search is    

int index1;  //index for where cursor of return value from PC is

unsigned char blank_clear;  //a state variable that decides what on the screen has been cleared on a PC return of data

unsigned char done_clear;  //indicates that all screen clearing has been finished

unsigned char from_pc;  //indicates if input over SPI is from keyboard or PC              

unsigned char tv_position;  //indicates which parameter returned by the PC is being output to the TV

unsigned char not_displayed;  //indicates if a character is unknown and thus not to be displayed

 

//Point plot lookup table  

//One bit masks

flash char pos[8]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01};                 

 

//define some character bitmaps

//5x7 characters

flash char bitmap[41][7]={

      //0

      0b01110000,

      0b10001000,

      0b10011000,

      0b10101000,

      0b11001000,

      0b10001000,

      0b01110000,

      //1

      0b00100000,

      0b01100000,

      0b00100000,

      0b00100000,

      0b00100000,

      0b00100000,

      0b01110000, 

      //2

      0b01110000,

      0b10001000,

      0b00001000,

      0b00010000,

      0b00100000,

      0b01000000,

      0b11111000,

      //3

      0b11111000,

      0b00010000,

      0b00100000,

      0b00010000,

      0b00001000,

      0b10001000,

      0b01110000,

      //4

      0b00010000,

      0b00110000,

      0b01010000,

      0b10010000,

      0b11111000,

      0b00010000,

      0b00010000,

      //5

      0b11111000,

      0b10000000,

      0b11110000,

      0b00001000,

      0b00001000,

      0b10001000,

      0b01110000,

      //6

      0b01000000,

      0b10000000,

      0b10000000,

      0b11110000,

      0b10001000,

      0b10001000,

      0b01110000,

      //7

      0b11111000,

      0b00001000,

      0b00010000,

      0b00100000,

      0b01000000,

      0b10000000,

      0b10000000,

      //8

      0b01110000,

      0b10001000,

      0b10001000,

      0b01110000,

      0b10001000,

      0b10001000,

      0b01110000,

      //9

      0b01110000,

      0b10001000,

      0b10001000,

      0b01111000,

      0b00001000,

      0b00001000,

      0b00010000, 

      //A

      0b01110000,

      0b10001000,

      0b10001000,

      0b10001000,

      0b11111000,

      0b10001000,

      0b10001000,

      //B

      0b11110000,

      0b10001000,

      0b10001000,

      0b11110000,

      0b10001000,

      0b10001000,

      0b11110000,

      //C

      0b01110000,

      0b10001000,

      0b10000000,

      0b10000000,

      0b10000000,

      0b10001000,

      0b01110000,

      //D

      0b11110000,

      0b10001000,

      0b10001000,

      0b10001000,

      0b10001000,

      0b10001000,

      0b11110000,

      //E

      0b11111000,

      0b10000000,

      0b10000000,

      0b11111000,

      0b10000000,

      0b10000000,

      0b11111000,

      //F

      0b11111000,

      0b10000000,

      0b10000000,

      0b11111000,

      0b10000000,

      0b10000000,

      0b10000000,

      //G

      0b01110000,

      0b10001000,

      0b10000000,

      0b10011000,

      0b10001000,

      0b10001000,

      0b01110000,

      //H

      0b10001000,

      0b10001000,

      0b10001000,

      0b11111000,

      0b10001000,

      0b10001000,

      0b10001000,

      //I

      0b01110000,

      0b00100000,

      0b00100000,

      0b00100000,

      0b00100000,

      0b00100000,

      0b01110000,

      //J

      0b00111000,

      0b00010000,

      0b00010000,

      0b00010000,

      0b00010000,

      0b10010000,

      0b01100000,

      //K

      0b10001000,

      0b10010000,

      0b10100000,

      0b11000000,

      0b10100000,

      0b10010000,

      0b10001000,

      //L

      0b10000000,

      0b10000000,

      0b10000000,

      0b10000000,

      0b10000000,

      0b10000000,

      0b11111000,

      //M

      0b10001000,

      0b11011000,

      0b10101000,

      0b10101000,

      0b10001000,

      0b10001000,

      0b10001000,

      //N

      0b10001000,

      0b10001000,

      0b11001000,

      0b10101000,

      0b10011000,

      0b10001000,

      0b10001000,

      //O

      0b01110000,

      0b10001000,

      0b10001000,

      0b10001000,

      0b10001000,

      0b10001000,

      0b01110000,

      //P

      0b11110000,

      0b10001000,

      0b10001000,

      0b11110000,

      0b10000000,

      0b10000000,

      0b10000000,

      //Q

      0b01110000,

      0b10001000,

      0b10001000,

      0b10001000,

      0b10101000,

      0b10010000,

      0b01101000,

      //R

      0b11110000,

      0b10001000,

      0b10001000,

      0b11110000,

      0b10100000,

      0b10010000,

      0b10001000,

      //S

      0b01111000,

      0b10000000,

      0b10000000,

      0b01110000,

      0b00001000,

      0b00001000,

      0b11110000,

      //T

      0b11111000,

      0b00100000,

      0b00100000,

      0b00100000,

      0b00100000,

      0b00100000,

      0b00100000,

      //U

      0b10001000,

      0b10001000,

      0b10001000,

      0b10001000,

      0b10001000,

      0b10001000,

      0b01110000,

      //V

      0b10001000,

      0b10001000,

      0b10001000,

      0b10001000,

      0b10001000,

      0b01010000,

      0b00100000,

      //W

      0b10001000,

      0b10001000,

      0b10001000,

      0b10101000,

      0b10101000,

      0b10101000,

      0b01010000,

      //X

      0b10001000,

      0b10001000,

      0b01010000,

      0b00100000,

      0b01010000,

      0b10001000,

      0b10001000,

      //Y

      0b10001000,

      0b10001000,

      0b10001000,

      0b01010000,

      0b00100000,

      0b00100000,

      0b00100000,

      //Z

      0b11111000,

      0b00001000,

      0b00010000,

      0b00100000,

      0b01000000,

      0b10000000,

      0b11111000,

      //figure1

      0b01110000,

      0b00100000,

      0b01110000,

      0b10101000,

      0b00100000,

      0b01010000,

      0b10001000,

      //figure2

      0b01110000,

      0b10101000,

      0b01110000,

      0b00100000,

      0b00100000,

      0b01010000,

      0b10001000,

      //<space> = ']'

      0b00000000,

      0b00000000,

      0b00000000,

      0b00000000,

      0b00000000,

      0b00000000,

      0b00000000,

      //.

      0b00000000,

      0b00000000,

      0b00000000,

      0b00000000,

      0b00000000,

      0b01000100,

      0b00000000,

      //:   

      0b00000000,

      0b01000100,

      0b00000000,

      0b00000000,

      0b00000000,

      0b01000100,

      0b00000000

};

 

 

//================================

//3x5 font numbers, then letters

//packed two per definition for fast

//copy to the screen at x-position divisible by 4

flash char smallbitmap[39][5]={

      //0

      0b11101110,

      0b10101010,

      0b10101010,

      0b10101010,

      0b11101110,

      //1

      0b01000100,

      0b11001100,

      0b01000100,

      0b01000100,

      0b11101110,

      //2

      0b11101110,

      0b00100010,

      0b11101110,

      0b10001000,

      0b11101110,

      //3

      0b11101110,

      0b00100010,

      0b11101110,

      0b00100010,

      0b11101110,

      //4

      0b10101010,

      0b10101010,

      0b11101110,

      0b00100010,

      0b00100010,

      //5

      0b11101110,

      0b10001000,

      0b11101110,

      0b00100010,

      0b11101110,

      //6

      0b11001100,

      0b10001000,

      0b11101110,

      0b10101010,

      0b11101110,

      //7

      0b11101110,

      0b00100010,

      0b01000100,

      0b10001000,

      0b10001000,

      //8

      0b11101110,

      0b10101010,

      0b11101110,

      0b10101010,

      0b11101110,

      //9

      0b11101110,

      0b10101010,

      0b11101110,

      0b00100010,

      0b01100110,

      //:

      0b00000000,

      0b01000100,

      0b00000000,

      0b01000100,

      0b00000000,

      //   

      0b00000000,

      0b11101110,

      0b00000000,

      0b11101110,

      0b00000000,

      //blank

      0b00000000,

      0b00000000,

      0b00000000,

      0b00000000,

      0b00000000,

      //A

      0b11101110,

      0b10101010,

      0b11101110,

      0b10101010,

      0b10101010,

      //B

      0b11001100,

      0b10101010,

      0b11101110,

      0b10101010,

      0b11001100,

      //C

      0b11101110,

      0b10001000,

      0b10001000,

      0b10001000,

      0b11101110,

      //D

      0b11001100,

      0b10101010,

      0b10101010,

      0b10101010,

      0b11001100,

      //E

      0b11101110,

      0b10001000,

      0b11101110,

      0b10001000,

      0b11101110,

      //F

      0b11101110,

      0b10001000,

      0b11101110,

      0b10001000,

      0b10001000,

      //G

      0b11101110,

      0b10001000,

      0b10001000,

      0b10101010,

      0b11101110,

      //H

      0b10101010,

      0b10101010,

      0b11101110,

      0b10101010,

      0b10101010,

      //I

      0b11101110,

      0b01000100,

      0b01000100,

      0b01000100,