//------------------------------------------------------------------------------------ // lcd_init //------------------------------------------------------------------------------------ // void lcd_init(void) { char SFRPAGE_SAVE; SFRPAGE_SAVE = SFRPAGE; // Save Current SFR page SFRPAGE = CONFIG_PAGE; LCD_CTRL_PORT = LCD_CTRL_PORT & ~RS_MASK; // RS = 0 LCD_CTRL_PORT = LCD_CTRL_PORT & ~RW_MASK; // RW = 0 LCD_CTRL_PORT = LCD_CTRL_PORT & ~E_MASK; // E = 0 large_delay(200); // 16ms delay LCD_DAT_PORT = 0x38; // set 8-bit mode small_delay(1); //RPK pulse_E(); large_delay(50); // 4.1ms delay [50] LCD_DAT_PORT = 0x38; // set 8-bit mode small_delay(1); //RPK pulse_E(); large_delay(3); // 1.5ms delay [2] LCD_DAT_PORT = 0x38; // set 8-bit mode small_delay(1); //RPK pulse_E(); large_delay(3); // 1.5ms delay [2] lcd_cmd(0x06); // curser moves right lcd_clear(); lcd_cmd(0x0E); // display and curser on SFRPAGE = SFRPAGE_SAVE; // Restore SFR page }
//------------------------------------------------------------------------------------ // lcd_busy_wait //------------------------------------------------------------------------------------ // // wait for the busy bit to drop // void lcd_busy_wait(void) { char SFRPAGE_SAVE; SFRPAGE_SAVE = SFRPAGE; // Save Current SFR page SFRPAGE = CONFIG_PAGE; LCD_DAT_PORT = 0xFF; // Set to FF to enable input on P6 LCD_CTRL_PORT = LCD_CTRL_PORT & ~RS_MASK; // RS = 0 LCD_CTRL_PORT = LCD_CTRL_PORT | RW_MASK; // RW = 1 small_delay(3); // [1 was original delay value] LCD_CTRL_PORT = LCD_CTRL_PORT | E_MASK; // E = 1 //TB_GREEN_LED = 1; do { // wait for busy flag to drop small_delay(2); // [1 was original delay value] } while ((LCD_DAT_PORT & 0x80) != 0); //TB_GREEN_LED = 0; SFRPAGE = SFRPAGE_SAVE; // Restore SFR page }
void radiotimer_cb_overflow(void) { // toggle pin debugpins_slot_toggle(); // switch radio LED on leds_radio_toggle(); // increment counter app_dbg.radiotimer_num_overflow++; // wait a bit small_delay(); }
//------------------------------------------------------------------------------------ // lcd_cmd //------------------------------------------------------------------------------------ // // write a command to the LCD controller // void lcd_cmd(char cmd) { char SFRPAGE_SAVE; SFRPAGE_SAVE = SFRPAGE; // Save Current SFR page SFRPAGE = CONFIG_PAGE; lcd_busy_wait(); LCD_CTRL_PORT = LCD_CTRL_PORT & ~RS_MASK; // RS = 0 LCD_CTRL_PORT = LCD_CTRL_PORT & ~RW_MASK; // RW = 0 LCD_DAT_PORT = cmd; small_delay(1); //RPK pulse_E(); SFRPAGE = SFRPAGE_SAVE; // Restore SFR page }
void bsp_timer_cb_compare(void) { // toggle pin debugpins_frame_toggle(); // toggle error led leds_error_toggle(); // increment counter app_dbg.bsp_timer_num_compare++; // schedule again bsp_timer_scheduleIn(BSP_TIMER_PERIOD); // wait a bit small_delay(); }
void main() { int x, y, w, h; clg(); while (1) { x = rand() % (getmaxx() ); y = rand() % (getmaxy() ); w = rand() % 16 + 4; h = rand() % 16 + 4; drawb(x, y, w, h); small_delay(); if (getk() == 10) { break; } // enter key is assigned to 10 } }
//------------------------------------------------------------------------------------ // lcd_dat (putchar) //------------------------------------------------------------------------------------ // // write a character to the LCD screen // char lcd_dat(char dat) //char putchar(char dat) { char SFRPAGE_SAVE; SFRPAGE_SAVE = SFRPAGE; // Save Current SFR page SFRPAGE = CONFIG_PAGE; lcd_busy_wait(); LCD_CTRL_PORT = LCD_CTRL_PORT | RS_MASK; // RS = 1 LCD_CTRL_PORT = LCD_CTRL_PORT & ~RW_MASK; // RW = 0 LCD_DAT_PORT = dat; small_delay(1); //RPK pulse_E(); SFRPAGE = SFRPAGE_SAVE; // Restore SFR page return 1; }
int main(void) { // prepare whistles outp(0xff, DDRA); outp(0x00, PORTA); // setup POT as tristate (and INT0=POTX as input) outp(0x00, POTPORT); outp(0x00, POTDDR); // enable irqs sbi(MCUCR, ISC01); cbi(MCUCR, ISC00); // int0 on falling // cbi(MCUCR, ISC01); cbi(MCUCR, ISC00); // int0 on low level sbi(GIMSK, INT0); // enable int0 // setup/enable irq from int0 sei(); while (TRUE) { small_delay(200); blink2(); } }
void draw_piano() { unsigned char ix=0; unsigned char jx=0; ET1=0; line(1,0,0,0,63); small_delay(300); line(1,0,63,127,63); small_delay(300); line(1,127,0,127,63); small_delay(300); pixel(1,1,0); small_delay(300); pixel(1,2,1); small_delay(300); for(ix=0;ix<127;ix++) { line(1,ix,23,ix,63); switch(ix) { case 7: ix=20; break; case 28: ix=41; break; case 49: ix=62; break; case 70: ix=83; break; case 91: ix=104; break; case 112: ix=200; break; default: break; } small_delay(300); } ix=0; for(ix=14;ix<127;ix = ix + 21) { line(1,ix,2,ix,63); small_delay(300); } ix=5; jx=12; while(ix<128) { line(1,ix,0,jx,0); small_delay(700); pixel(1,ix-1,1); small_delay(700); pixel(1,jx+1,1); if(ix<115) { small_delay(700); line(1,ix-2,2,ix-2,22); } switch(ix) { case 5: ix=16; jx=23; break; case 16: ix=27; jx=33; break; case 27: ix=37; jx=43; break; case 37: ix=47; jx=54; break; case 47: ix=58; jx=65; break; case 58: ix=69; jx=75; break; case 69: ix=79; jx=85; break; case 79: ix=89; jx=96; break; case 89: ix=100; jx=107; break; case 100: ix=111; jx=118; break; case 111: ix=122; jx=125; break; case 122: ix=200; jx=0; break; default: break; } small_delay(700); } putchar(0x7C); putchar(0x02); putchar(0x7F); ET1=1; }
void draw_drums() { circle(1,17,17,17); small_delay(700); set_text_position(17,17); small_delay(700); printf("1"); small_delay(700); circle(1,41,45,16); small_delay(700); set_text_position(41,45); small_delay(700); printf("2"); small_delay(700); circle(1,64,17,17); small_delay(700); set_text_position(64,17); small_delay(700); printf("3"); small_delay(700); circle(1,86,45,16); small_delay(700); set_text_position(86,45); small_delay(700); printf("4"); small_delay(700); circle(1,109,17,17); small_delay(700); circle(1,109,17,13); small_delay(700); circle(1,109,17,9); small_delay(700); circle(1,109,17,5); small_delay(700); }
int GPIO_Mask_OP(void) { int err_code = 0, err_code_all = 0; uint32_t i = 0, random_mask = 0, exp_value = 0, random_value, prev_masks[2] = { 0 }, mask = 0; CMSDK_gpio_SetOutEnable(CMSDK_GPIO0, 0xFFFF); CMSDK_GPIO0->DATAOUT = 0x0000; puts("Stage 4 - GPIO Masked Output Test\n"); puts("- Stage 4a - GPIO Masked Output - Deterministic Test\n"); for(i = 0; i < 16; i++){ CMSDK_gpio_MaskedWrite(CMSDK_GPIO0, 0xFFFF, (1 << i)); //test each pin on the GPIO to check that masked small_delay(); //access works for each pin individually if(CMSDK_GPIO0->DATA != (0xFFFF & (1 << i))) err_code |= (1 << i); CMSDK_gpio_MaskedWrite(CMSDK_GPIO0, 0x0000, (1 << i)); //clear value back to zero small_delay(); } CMSDK_GPIO0->DATAOUT = 0; for(i = 0; i < 16; i++){ CMSDK_gpio_MaskedWrite(CMSDK_GPIO0, 0xFFFF, (1 << i)); //test each pin on the GPIO to check that masked small_delay(); //access works for each pin individually mask |= (1 << i); if(CMSDK_GPIO0->DATA != (0xFFFF & mask)) //test do not reset to ensure that the masked output err_code |= (1 << (i + 16)); //goes through the transition 0001->0011->0111->1111 small_delay(); } if(!err_code) puts("Stage 4a Deterministic Masked Output Tests Passed Successfully\n"); else { printf("\nStage 4a Deterministic Masked Output Tests Failed, Error Code: (0x%x)\n", err_code); err_code_all |= 1; } puts("- Stage 4b - GPIO Masked Output - Random Test\n"); err_code = 0; CMSDK_GPIO0->DATAOUT = 0; srand(RANDOM_NUMBER); for(i = 0; i < 16; i++){ //repeat same process but with 16 random mask random_mask = (rand() % 65536); //values, the random function is seeded with a CMSDK_gpio_MaskedWrite(CMSDK_GPIO0, 0xFFFF, random_mask); //#define at the top of the program called RANDOM_NUMBER if(CMSDK_GPIO0->DATA != (0xFFFF & random_mask)) //can be easily changed to perform tests on 16 err_code |= (1 << i); // more different random numbers CMSDK_gpio_MaskedWrite(CMSDK_GPIO0, 0x0000, random_mask); } CMSDK_GPIO0->DATAOUT = 0; mask = 0; for(i = 0; i < 16; i++){ //repeat same process but with 16 random mask values, random_mask = (rand() % 65536); //which are only cleared every other iteration so that random_value = (rand() % 65536); //they accumulate, the first value is outputted using //masked access and then not cleared then a second value if(prev_masks[0] == 0) prev_masks[0] = random_mask; //is outputted using another mask and then the resulting else prev_masks[1] = random_mask; //output is then checked against the expected output exp_value = ((random_mask & random_value) | (exp_value & ~random_mask)); CMSDK_gpio_MaskedWrite(CMSDK_GPIO0, random_value, random_mask); if(CMSDK_GPIO0->DATA != exp_value) err_code |= (1 << (i + 16)); /* For every two non-zero mask writes taken place, reset the data using the stored mask value and clear the exp_value back to 0 */ if((prev_masks[0] != 0) && (prev_masks[1] != 0)){ CMSDK_gpio_MaskedWrite(CMSDK_GPIO0, 0x0000, prev_masks[0]); CMSDK_gpio_MaskedWrite(CMSDK_GPIO0, 0x0000, prev_masks[1]); prev_masks[0] = 0; prev_masks[1] = 0; exp_value = 0; } } if(!err_code) puts("Stage 4b Random Masked Output Tests Passed Successfully\n"); else { printf("\nStage 4b Random Masked Output Tests Failed, Error Code: (0x%x)\n", err_code); err_code_all |= 2; } if(!err_code_all) puts("\nAll Masked Output Tests Passed Successfully\n"); if(!err_code_all) return 0; else return 4; }
void large_delay(char d) { while (d--) small_delay(255); }
void draw_drums() { ///EA = 0; circle(1,17,17,17); small_delay(700); set_text_position(17,17); small_delay(700); tx0_send("1", 1); small_delay(700); circle(1,41,45,16); small_delay(700); set_text_position(41,45); small_delay(700); tx0_send("2", 1); small_delay(700); circle(1,64,17,17); small_delay(700); set_text_position(64,17); small_delay(700); tx0_send("3", 1); small_delay(700); circle(1,86,45,16); small_delay(700); set_text_position(86,45); small_delay(700); tx0_send("4", 1); small_delay(700); circle(1,109,17,17); small_delay(700); circle(1,109,17,13); small_delay(700); circle(1,109,17,9); small_delay(700); circle(1,109,17,5); small_delay(700); //EA = 1; }