/* NOT REAL CODE Golf.c Description: Golf. Authors: Eli Rosofsky and Evan Hopkins */ #include #include // sprintf #include "golf.h" #include #include #define nopush 0 #define maybepush 1 #define pushed 2 #define maybeno 3 #define LATCH PORTC.2 #define PULSE PORTC.1 #define NOP 0x00 #define t1 250 #define t2 250 //#define LCDwidth 16 #define LCDreset 0x00 // Reset the Display #define LCDnop 0xb8 // 47No operation #define CmdSetup 0xb8 // 47Set A0 high #define CmdWrite 0x98 // 43Set WR low #define DataSetup 0x38 // 07Set A0 low #define DataWrite 0x18 // 03Set WR low #define StatusRead 0x28 // 05Set RD low, A0 low #define DataRead 0xa8 // 45Set RD low, A0 high // LCD Commands (PORTD) #define SystemSet 0x40 // Initialize system #define SleepIn 0x53 // Enter standby mode #define DispOFF 0x58 // Display Off #define DispON 0x59 // Display On #define Scroll 0x44 // Initialize Address & Regions #define CSRForm 0x5D // Set cursor type #define CharAddr 0x5C // Set address of character RAM #define CSRRight 0x4C // Cursor direction = right #define CSRLeft 0x4D // Cursor direction = left #define CSRUp 0x4E // Cursor direction = up #define CSRDown 0x4F // Cursor direction = down #define HorzScroll 0x5A // Set horz scroll position #define Overlay 0x5B // Set Display Format #define CSRW 0x46 // Set cursor address #define CSRR 0x47 // Read cursor address #define MWRITE 0x42 // Write to display memory #define MREAD 0x43 // Read from display memory // Global Constants #define TextAddress 0x0000 // Character layer base address #define GraphicsAddress 0x03E8 // Graphics layer base address = 1000 #define NUM_TEXT_LINES 16 // 128 / 8 = 16 character lines #define NUM_GRAPHICS_LINES 128 // 128 / 1 = 128 graphics lines #define BYTES_PER_LINE 32 // 256 / 8 = 32 bytes per line #define GRAPHICS 1 #define TEXT 0 #define ON 1 #define OFF 0 #define MENU_OFFSET 18 //offset of text to be on the Menu side of the screen #define STROKE_POSX 27 //For printing the stroke #define STROKE_POSY 9 #define CLUB_POSX 25 #define CLUB_POSY 10 flash unsigned char SCLUB[] = {'S','e','l','e','c','t',' ','C','l','u','b'}; flash unsigned char SDIR[] = {'S','e','l','e','c','t',' ','D','i','r','.'}; flash unsigned char PRESSUPDOWN[] = {'P','r','e','s','s',' ','U','P','/','D','O','W','N',','}; flash unsigned char PRESSA[] = {'A',' ','t','o',' ','s','e','t'}; flash unsigned char STROKE[] = {'S','t','r','o','k','e',' ','=',' ',' ','/','9'}; flash unsigned char CLUB[] = {'C','l','u','b',' ','='}; flash unsigned char PUTTERCHAR[] = {'P','u','t','t','e','r'}; flash unsigned char SWEDGECHAR[] = {'S','.',' ','W','e','d','g','e'}; flash unsigned char IRONCHAR[] = {'I','r','o','n'}; flash unsigned char WOODCHAR[] = {'W','o','o','d'}; flash unsigned char PRESSPAD[] = {'P','r','e','s','s',' ','D','I','R',' ','P','A','D',','}; flash unsigned char CLEARLINE[] = {' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '}; /* PROTOTYPES */ void initialize(void); void task1(void); void getInput(void); void initLCD(void); void WriteCMD(unsigned char CommandCode); void WriteDATA(unsigned char CommandCode); void clearLCD(void); void GotoXY(unsigned char x, unsigned char y, unsigned char isGraphics); void vertical_line(unsigned char x); char ReadDATA(void); void setPixel(char x, char y, char pixState); void circle(char x_ctr,char y_ctr,char radius,char pen_size,char state); void line(char x1,char y1,char x2,char y2,char line_state); void draw_menu(void); void printFlash (unsigned char x_coord, unsigned char y_coord, unsigned char* array); void drawSplash (void); void drawCourse(void); void changeClub(signed char inc); /* FLASH VARIABLES */ unsigned char E [] = {1, 5, 0xf8, 0x80, 0xe0, 0x80, 0xf8}; flash unsigned char L [] = {1, 5, 0x80, 0x80, 0x80, 0x80, 0xf8}; flash unsigned char I [] = {1, 5, 0xf8, 0x20, 0x20, 0x20, 0x20, 0xf8}; unsigned char OO [] = {1, 4, 0x60, 0x90, 0x90, 0x60}; unsigned char o [] = {1, 3, 0x70, 0x50, 0x70}; unsigned char XX [] = {1, 5, 0x22, 0x14, 0x08, 0x14, 0x22}; unsigned char x [] = {1, 3, 0x05, 0x02, 0x05}; flash unsigned char ELI [] = {3, 5, 0xf8, 0x80, 0xf8, 0x80, 0x80, 0x20, 0xe0, 0x80, 0x20, 0x80, 0x80, 0x20, 0xf8, 0xf8, 0xf8}; flash unsigned char SAND1 [] = {1, 8, 0x18, 0x3c, 0x7e, 0xff, 0xff, 0x7e, 0x3c, 0x18}; flash unsigned char SAND2 [] = {2, 10, 0x0f, 0xc0, 0x3f, 0xc0, 0x3f, 0xc0, 0x7f, 0xc0, 0x7f, 0xc0, 0xff, 0xc0, 0xf3, 0xc0, 0xe3, 0xc0, 0xe3, 0xc0, 0x41, 0xc0}; /* VARIABLES */ unsigned char time1,time2; //unsigned char reload; unsigned char direction; //direction entered unsigned char state, cont_state; //state variables unsigned char buttonpushed; //Mask for pushed buttons unsigned char button_check; //for what button is being checked on input signed char club; //club entered unsigned char input; //the input mask that is incrementally updated unsigned char ball_x; //global x coordinate for the ball unsigned char ball_y; //global y-coordinate for the ball unsigned char hole_x; //global x-coordinate for the hole unsigned char hole_y; //global y-coordinate for the hole unsigned char animPathX[16]; //X coordinates for the animation unsigned char animPathY[16]; //Y coordinates for the animation signed char power; //power entered unsigned char animation_done; unsigned char counter; unsigned long int random_int; //hold a 32-bit random int //********************************************************* /* INTERRUPTS */ //********************************************************** //timer 1 compare-match A ISR interrupt [TIM1_COMPA] void cmpA_overflow(void) begin if (time1 > 0) --time1; if (time2 > 0) --time2; end //********************************************************** /* MAIN */ //********************************************************** //Entry point and task scheduler loop void main(void) begin initialize(); initLCD(); clearLCD(); drawSplash(); //main task scheduler loop while(1) begin ++random_int; if (time1==0) task1(); if (time2==0) getInput(); end end /***********************************************************/ /* TASKS */ /***********************************************************/ void task1() begin int i; time1 = t1; LED = ~buttonpushed; /* Reset */ if (buttonpushed == RESET_KEY) begin state = start_screen; clearLCD(); drawSplash(); end switch(state) begin /* Start Screen */ case start_screen: if (buttonpushed == START) begin clearLCD(); drawCourse(); //draw course, sand, hole, ball state = select_club; buttonpushed = 0; draw_menu(); //********************************************* // Print Instructions //********************************************* GotoXY(MENU_OFFSET, NUM_TEXT_LINES-2, TEXT); WriteCMD(MWRITE); for(i = 0; i < sizeof(SCLUB); i++) WriteDATA(SCLUB[i]); GotoXY(MENU_OFFSET, NUM_TEXT_LINES-1, TEXT); WriteCMD(MWRITE); for(i = 0; i < sizeof(PRESSUPDOWN); i++) WriteDATA(PRESSUPDOWN[i]); GotoXY(MENU_OFFSET, NUM_TEXT_LINES, TEXT); WriteCMD(MWRITE); for(i = 0; i < sizeof(PRESSA); i++) WriteDATA(PRESSA[i]); end break; /* Select Club */ case select_club: if (buttonpushed != 0) begin if (buttonpushed & DOWN) changeClub(-1); else if (buttonpushed & UP) changeClub(1); else if (buttonpushed & A_BUT) begin club = buttonpushed; //in range [0,3] state = select_dir; //********************************************* // Print Instructions //********************************************* GotoXY(MENU_OFFSET, NUM_TEXT_LINES-2, TEXT); WriteCMD(MWRITE); for(i = 0; i < sizeof(CLEARLINE); i++) WriteDATA(CLEARLINE[i]); GotoXY(MENU_OFFSET, NUM_TEXT_LINES-2, TEXT); WriteCMD(MWRITE); for(i = 0; i < sizeof(SDIR); i++) WriteDATA(SDIR[i]); GotoXY(MENU_OFFSET, NUM_TEXT_LINES-2, TEXT); WriteCMD(MWRITE); for(i = 0; i < sizeof(CLEARLINE); i++) WriteDATA(CLEARLINE[i]); GotoXY(MENU_OFFSET, NUM_TEXT_LINES-1, TEXT); WriteCMD(MWRITE); for(i = 0; i < sizeof(PRESSPAD); i++) WriteDATA(PRESSPAD[i]); end end break; /* Select Direction */ case select_dir: // while (! BUT_A) // direction = buttonpushed; if (buttonpushed > 0x0f) begin direction = buttonpushed >> 4; state = select_power; // Show Direction - updateLCD2() end break; /* Select Power */ case select_power: if (++power > 9) begin power = 0; end // Show Power bar on LCD - updateLCD3() // get Power if (buttonpushed == A_BUT) begin //++stroke state = animation; //calculate new ball position, store interim positions //might require new variables end break; /* Sand Trap? */ case check_sand: //read_lcd(new_ball_position); //if (dark) // inSand = TRUE //else not in sand // inSand = FALSE state = animation; break; /* Animation */ case animation: //loop through interim ball positions, displaying // ball at each new position // when (animation_done) state = check_hole; break; /* Check Hole */ case check_hole: // if (|x|+|y|> 28) & 0x0f; //bits [31..28] sand1_y = (random_int >> 21) & 0x7f; //bits [27..20] sand2_x = random_int & 0x0f; //bits [3..0] sand2_y = (random_int >> 13) & 0x7f; //bits [19..13] sand3_x = (random_int >> 4) & 0x0f; //bits [7..4] sand3_y = (random_int >> 7) & 0x7f; //bits [13..7] //hole must be in top half (y=[0,63]) hole_x = (random_int >> 12) & 0x0f; //bits [15..12] hole_y = (random_int >> 9) & 0x3f; //bits [14..9] //tee must be in lower half (y=[64,127]) ball_x = (random_int >> 26) & 0x0f; //bits [29..26] ball_y = ((random_int >> 15) & 0x3f) | 0x70; //bits[20..15] + 0x70; printFlash(sand1_x, sand1_y, XX); // printFlash(sand2_x, sand2_y, x); // printFlash(sand3_x, sand3_y, E); // printFlash(hole_x, hole_y, OO); // printFlash(ball_x, ball_y, o); // end /*********************************************************************/ /* LCD COMMANDS */ /*********************************************************************/ /* printFlash(char x, char y, char* array): (byte x, bit y) coordinates to draw the E */ /*********************************************************************/ void printFlash (unsigned char x_coord, unsigned char y_coord, unsigned char* array) { unsigned char x, y; //dimensions of graphic unsigned char x_itr, y_itr; //loop variables unsigned char array_itr; x = array[0]; //index 0 y = array[1]; //index 1 array_itr = 2; //start building graphic with third index [2] for (y_itr = y_coord; y_itr < y+y_coord+1; y_itr++) { GotoXY(x_coord+1,y_coord+y_itr+1, GRAPHICS); WriteCMD(MWRITE); for (x_itr = 0; x_itr < x; x_itr++) { WriteDATA( array[array_itr] ); ++array_itr; } } } /********************************************************************** Function Name: drawSplash() Purpose: Displays the Instructions on the screen, and says press start to continue Input Vars: None Return value: None **********************************************************************/ void drawSplash(void) begin GotoXY(14,3,TEXT); WriteCMD(MWRITE); WriteDATA('G'); WriteDATA('o'); WriteDATA('l'); WriteDATA('f'); WriteDATA(' '); WriteDATA('v'); WriteDATA('1'); WriteDATA('.'); WriteDATA('0'); GotoXY(12,8,TEXT); WriteCMD(MWRITE); WriteDATA('P'); WriteDATA('r'); WriteDATA('e'); WriteDATA('s'); WriteDATA('s'); WriteDATA(' '); WriteDATA('S'); WriteDATA('T'); WriteDATA('A'); WriteDATA('R'); WriteDATA('T'); end /*********************************************************************/ /* drawmenu(): draws the right side of the play screen */ /*********************************************************************/ void draw_menu(void) begin //Right side of the screen starts around text (17, 1) int i; //********************************************* // Draws Dividers //********************************************* line(128, 0, 128, 128, ON); //draw divider line(178, 0, 178, 60, ON); //power/direction divider line(128, 60, 256, 60, ON); //menu horizontal divider //********************************************* // Draws Direction Compass //********************************************* circle(220, 35, 15, 2, ON); //draw compass setPixel(220, 35, ON); line(205, 35, 220, 35, ON); //default direction is North //********************************************* // Writes Titles //********************************************* GotoXY(24, 1, TEXT); WriteCMD(MWRITE); WriteDATA('D'); WriteDATA('i'); WriteDATA('r'); WriteDATA('e'); WriteDATA('c'); WriteDATA('t'); WriteDATA('i'); WriteDATA('o'); WriteDATA('n'); GotoXY(18, 1, TEXT); WriteCMD(MWRITE); WriteDATA('P'); WriteDATA('o'); WriteDATA('w'); WriteDATA('e'); WriteDATA('r'); //********************************************* // Draws Power Box //********************************************* line(150,20,150,50,ON); line(158,20,158,50,ON); line(150,20,158,20,ON); line(150,50,158,50,ON); setPixel(150,20, ON); //********************************************* // Draws Strokes //********************************************* GotoXY(MENU_OFFSET, STROKE_POSY, TEXT); WriteCMD(MWRITE); for(i = 0; i < sizeof(STROKE); i++) WriteDATA(STROKE[i]); GotoXY(STROKE_POSX, STROKE_POSY, TEXT); WriteCMD(MWRITE); WriteDATA('0'); //********************************************* // Draws Club //********************************************* GotoXY(MENU_OFFSET, CLUB_POSY, TEXT); WriteCMD(MWRITE); for(i = 0; i < sizeof(CLUB); i++) WriteDATA(CLUB[i]); GotoXY(CLUB_POSX, CLUB_POSY, TEXT); WriteCMD(MWRITE); for(i = 0; i < sizeof(PUTTERCHAR); i++) WriteDATA(PUTTERCHAR[i]); end /*********************************************************************/ /* changeClub(inc) : Increments club up/down depending on $inc */ /*********************************************************************/ void changeClub(signed char inc) begin int i; club = club + inc; if (club < PUTTER) club = WOOD; if (club > WOOD) club = PUTTER; GotoXY(CLUB_POSX, CLUB_POSY, TEXT); WriteCMD(MWRITE); if (club == PUTTER) begin for(i = 0; i < sizeof(PUTTERCHAR); i++) WriteDATA(PUTTERCHAR[i]); end if (club == SANDWEDGE) begin for(i = 0; i < sizeof(SWEDGECHAR); i++) WriteDATA(SWEDGECHAR[i]); end if (club == IRON) begin for(i = 0; i < sizeof(IRONCHAR); i++) WriteDATA(IRONCHAR[i]); end if (club == WOOD) begin for(i = 0; i < sizeof(WOODCHAR); i++) WriteDATA(WOODCHAR[i]); end end /*********************************************************************/ /* initLCD() : Initializes the LCD controller */ /*********************************************************************/ void initLCD(void) { // set I/O port directions DDRC = 0xFE; DDRD = 0xFF; PORTC = LCDnop; delay_us(500); delay_us(500); delay_us(500); delay_us(500); PORTC = LCDreset; delay_us(500); delay_us(500); delay_us(500); PORTC = LCDnop; delay_us(500); delay_us(500); delay_us(500); delay_us(500); WriteCMD(SystemSet); WriteDATA(0x30); WriteDATA(0x87); WriteDATA(0x07); WriteDATA(0x27); WriteDATA(0x2F); WriteDATA(0xC7); WriteDATA(0x28); //low-bit of AP WriteDATA(0x00); //high-bit of AP WriteCMD(Overlay); WriteDATA(0x00); WriteCMD(Scroll); WriteDATA(0x00); WriteDATA(0x00); WriteDATA(0xC8); WriteDATA(0xE8); WriteDATA(0x03); WriteDATA(0xC8); WriteCMD(CSRForm); WriteDATA(0x04); WriteDATA(0x86); WriteCMD(CSRRight); WriteCMD(HorzScroll); WriteDATA(0x00); WriteCMD(DispON); WriteDATA(0x14); //n0 cursor //WriteDATA(0x16); //cursor clearLCD(); WriteCMD(CSRW); WriteDATA(0x0A); WriteDATA(0x00); WriteCMD(MWRITE); WriteDATA('I'); WriteDATA('N'); WriteDATA('I'); WriteDATA('T'); WriteDATA('I'); WriteDATA('A'); WriteDATA('L'); WriteDATA('I'); WriteDATA('Z'); WriteDATA('I'); WriteDATA('N'); WriteDATA('G'); delay_ms(1500); return; } /*********************************************************************/ /* WriteCMD() : Sends Command to LCD controller */ /*********************************************************************/ void WriteCMD(unsigned char CommandCode) { PORTD = CommandCode; PORTC = CmdSetup; PORTC = CmdWrite; PORTC = CmdSetup; return; } /*********************************************************************/ /* WriteDATA() : Sends parameters or data to LCD controller */ /*********************************************************************/ void WriteDATA(unsigned char CommandCode) { PORTD = CommandCode; PORTC = DataSetup; PORTC = DataWrite; PORTC = DataSetup; return; } /*********************************************************************/ /* clearLCD() : Clears the LCD display memory */ /*********************************************************************/ void clearLCD(void) { unsigned short i; WriteCMD(CSRRight); WriteCMD(CSRW); WriteDATA(0x00); WriteDATA(0x00); WriteCMD(MWRITE); for (i=0; i<1000; i++) { WriteDATA(0x20); // write " " to character memory } WriteCMD(CSRW); WriteDATA(0xE8); WriteDATA(0x03); WriteCMD(MWRITE); for (i=0; i<8000; i++) { WriteDATA(0x00); // erase graphics memory } return; } /*********************************************************************/ /* GotoXY(char x_coordinate,char y_coordinate, unsigned char isGraphics): */ /* Goto location on LCD for printing /* ARGUMENTS: x - horizontal bytes from left. Range = [1,BYTES_PER_LINE] /* y - vertical pixels from top. Range = [1,NUM_GRAPHICS_LINES] /* isGraphics - as opposed to text. Uses different base addresses. /*********************************************************************/ void GotoXY(unsigned char x, unsigned char y, unsigned char isGraphics) { int Address; unsigned char low; unsigned char high; if (isGraphics == TEXT) x--; y--; Address = ((int)y * 40) + x; Address += (isGraphics * GraphicsAddress); low = (unsigned char) (Address & 0x00ff); high = (unsigned char) ((Address & 0xff00) >> 8); WriteCMD(CSRW); // CURSOR WRITE COMMAND WriteDATA(low); // Cursor position low byte WriteDATA(high); // Cursor position high byte } /*********************************************************************/ /* Set Pixel(x_coordinate, y coordinate, on or off): */ /* Set a pixel on/off (x <= 256, y <= 128 */ /*********************************************************************/ void setPixel(char x, char y, char pixState) begin char x_block, data, mask; x_block = floor(x / 8); //check later@@@@@@@@@@@@@@@@@@@@@@@@@&&&&&&&&&&&&&&&&& GotoXY(x_block, y, GRAPHICS); //get the pixel block and line data = ReadDATA(); mask = 0x80 >> (x & 0x07); //take the bottom 3 bits, and put if (pixState) begin data = data | mask; end else begin mask = ~mask; data = data & mask; end GotoXY(x_block, y, GRAPHICS); //get the pixel block and line WriteCMD(MWRITE); WriteDATA(data); end char ReadDATA(void) begin char data; PORTC.7 = 1; //A0 = 1; WriteCMD(MREAD); //lcd_send_data(command); DDRD = 0; //set_tris_b = 0xff; PORTC.7 = 1; //A0 = 1; delay_us(100); PORTC.4 = 0; //LCD_RD = 0; delay_us(2); data = PIND; //data = LCD_DATA_PORT; delay_us(2); PORTC.4 = 1; //LCD_RD = 1; delay_us(2); DDRD = 0xff; //set_tris_b = 0 return data; end /*********************************************************************/ /* line ( x1, y1, x2, y2, line_state): draw line from (x1,y1) */ /* to (x2,y2) with line_state = ON turns pixels on, OFF turns off */ /*********************************************************************/ void line(char x1,char y1,char x2,char y2,char line_state) { char i,line_length,x,y; signed long deltax,deltay,accm_error; signed long xchange,ychange; //long delay; // bresenham algorithm for lines x = x1; y = y1; deltax = (x2) - (x1); deltay = (y2) - (y1); ychange=1; xchange=1; if(deltax < 0) { xchange = -1; deltax = -deltax; } if(deltay < 0) { ychange = -1; deltay = -deltay; } accm_error = 0; i = 0 ; if(deltax < deltay) { // line_length = deltay + 1; line_length = deltay; while(i < line_length) { y = y + ychange ; accm_error = accm_error + deltax; if(accm_error > deltay) { x = x + xchange; accm_error = accm_error - deltay; } i = i + 1; setPixel(x,y,line_state); } } else { // line_length = deltax + 1; line_length = deltax; while(i < line_length) { x = x + xchange ; accm_error = accm_error + deltay; if(accm_error > deltax) { y = y + ychange; accm_error= accm_error - deltax; } i = i + 1; setPixel(x,y,line_state); } } } /*********************************************************************/ /* circle( x, y, radius, pen, circ_state): */ /*********************************************************************/ void circle(char x_ctr,char y_ctr,char radius,char pen_size,char circ_state) { char x,y,r,x1,y1,cx,cy; signed long delta; cx = x_ctr; cy = y_ctr; // y axis is shrunk to reflect the aspect ratio // this uses bresenham's algorithm // theory // 0=x^2+y^2-r^2 is true circle centered at 0,0 // error is x^2+y^2-r^2 // looking at north to north east octant // pixels are * 0 // 0 // algorithm chooses pixel due east or south east // * has the coord (x,y) both 0 pixels have an x coord of x+1 // mid pt has coord of (x+1,y+1/2) // error is (x+1)^2+(y+1/2)^2 -r^2 // error >0 draw south east ( x+1,y-1) pixel else draw east pixel (x+1,y) // now we can compute the error in advance for the next iteration // change in error from (x+1,y-1/2) to (x+2,y-1/2) is 2x+3 // (x+1,y-1/2) to (x+2,y-3/2) 2x+3 -2y+2 // Note: delta is the error in the code below // if delta is <0 then we decrement y r = 0x7F; if (radius<0x7F) r = radius; // max radius is 239 pixels for(r=radius-pen_size;r<=radius;r++) { x = 0; y = r; // assume last step was to south east pixel from (0,r) or 2*0-2*r+5 delta = (long)5 - (long)2 * (long)r; //loop: do begin // y1=(long)y*(long)11/(long)14; /// aspect ratio // x1=(long)x*(long)11/(long)14; /// aspect ratio y1 = y; // 1 to 1 x1 = x; // 1 to 1 setPixel(cx+x,cy+y1,circ_state); setPixel(cx+x,cy-y1,circ_state); setPixel(cx-x,cy+y1,circ_state); setPixel(cx-x,cy-y1,circ_state); setPixel(cx+y,cy+x1,circ_state); setPixel(cx+y,cy-x1,circ_state); setPixel(cx-y,cy+x1,circ_state); setPixel(cx-y,cy-x1,circ_state); if(delta < 0) delta = delta + (long)2 * (long)x + (long)3; else { delta = delta + (long)2 * ((long)x - (long)y) + (long)5; y = y - 1; } x = x + 1; end while (x<=y); } } /*********************************************************************/ /* vertical_line(char x_coordinate): draw a vertical line at byte number*/ /*********************************************************************/ void vertical_line (unsigned char x_coordinate) /* DOES WORK */ { long int address; char /*addrl, addrh,*/ i; address = 0x3E8; for (i = 0; i < NUM_GRAPHICS_LINES; ++i) { GotoXY(x_coordinate+1, i+1, GRAPHICS); /* addrl = (char)(0xff & address); addrl += x_coordinate; addrh = (char)(address >> 8); address += 40; WriteCMD(CSRW); WriteDATA(addrl); WriteDATA(addrh); */ WriteCMD(MWRITE); // for (j = 0; j < x_coordinate; ++j) // { // WriteDATA(0x00); // } WriteDATA(0xff);//WriteDATA(E[i+2]); } } /****************************************************/ /* MCU INITIALIZATION */ /****************************************************/ void initialize() begin // set up the ports // 0 is input 1 is output DDRC.0=0; //PortC Data in DDRC.1=1; //PortC Pulse DDRC.2=1; //PortC Latch DDRC.3=1; //PortC bit 0 is output, Reset DDRC.4=1; //PortC bit 1 is output, Read Strobe DDRC.5=1; //PortC bit 1 is output, Write Strobe DDRC.6=1; //PortC bit 5 is output, Chip Select DDRC.7=1; //PortC bit 6 is output, A0 /* PORT D */ DDRD.0=1; //PortD bit 0 is output, Data 0 DDRD.1=1; //PortD bit 1 is output, Data 1 DDRD.2=1; //PortD bit 2 is output, Data 2 DDRD.3=1; //PortD bit 3 is output, Data 3 DDRD.4=1; //PortD bit 3 is output, Data 4 DDRD.5=1; //PortD bit 3 is output, Data 5 DDRD.6=1; //PortD bit 3 is output, Data 6 DDRD.7=1; //PortD bit 3 is output, Data 7 // DDRB = 0xff; // PORTB = 0xff; // CTRL_DIR = 0xFE; // Set up Control Port // PIN 0 - Data In // PIN 1 - Pulse // PIN 2 - Latch LED_DIR=0xff; // LED is an ouput LED=0xff; // turn LED's OFF // set up timer 1 TIMSK = 0x10; // turn on timer 1 interrupt OCR1A = 1000; // time for 1080us per latch-train TCNT1 = 0; // zero the timer TCCR1B = clear_on_match + prescale1; // enable clear-on-match and set prescalar //prescalar is 1=>1, 2=>1/8, 3=>1/64, 4=>1/256, 5=>1/1024 //Set Up Timer Variables time1 = t1; time2 = t2; //Set Up States state = start_screen; cont_state = rest; power = 0; counter = 0; button_check=0; input = 0; club = PUTTER; //crank up the ISRs #asm("sei"); end