예제 #1
0
파일: abc_embox.c 프로젝트: Julia117/embox
static void display_x(uint8_t x, uint8_t y) {
	display_draw(x, y, 1, 8, &pict_buff11[0]);
	display_draw(x + 8, y, 1, 8, &pict_buff12[0]);
	display_draw(x + 4, y + 1, 1, 8, &pict_buff13[0]);
	display_draw(x, y + 2, 1, 8, &pict_buff12[0]);
	display_draw(x + 8, y + 2, 1, 8, &pict_buff11[0]);
	nxt_lcd_force_update();
}
예제 #2
0
int
main(int argv, char **argc)
{
  int i;
  sim_object_t * object;
  /*Create a sim_data object*/
  sim_data_t* test_sim = sim_new();
  sim_init(test_sim,1, 10, 192, 120);

  /*Create a display_state*/
  display_state_t * state = calloc(1,sizeof(display_state_t));
  /* memset(state, 0, sizeof(*state)); */
  bcm_egl_openvg_init(state);
  display_init(state, 0);
  state->showfps = true;
  /*
  for(i = 0; i < 1000; i++)
  */
  while(1)
  {
    sim_tick(test_sim);
    /*Pass to display and alter*/
    display_draw(state, test_sim);

    /*
    for(i = 0; i < test_sim->size; i++)
    {
      object = test_sim->objects[i];
      object->x += 1;
      object->y += 1;
    }
    */
  }
  return EXIT_SUCCESS;
}
예제 #3
0
void display_text(char *message, int row_cur, int col_cur){
    int i = 0, j, k;
    while(message[i]){      //reads through characters in message
        int ch_row = ascii_row(message[i]);     //gets row of character in ascii table
        //checking if pixel is out of bounds
        if(col_cur > 125){
            col_cur = 0;
            row_cur = row_cur + 8;
        }
        if(row_cur > 56){
            row_cur = 0;
            col_cur = 0;
        }
        int row = row_cur;
        int col = col_cur;

        //loops through columns and rows of each charcter pixel values
        for(j = 0; j < 5; j++){
            for(k = 0; k < 8; k++){
                int ch_hex = ASCII[ch_row][j];      //gets the pixel values from each column
                int ch_bin = (ch_hex & (1 << k)) >> k; //bitmask the value
                row = row_cur + k;
                col = col_cur + j;
                display_pixel_set(row, col, ch_bin); //set the pixel value
            };
        };
        i++;
        col_cur = col_cur + 5;
    };
    display_draw(); //draws the image
}
예제 #4
0
파일: pic_accel.c 프로젝트: mjc401/ME433
void accelerometer_test(void){
    unsigned char who,message[5];
    acc_read_register(WHO_AM_I,&who,1);
    sprintf(message,"%d",who);
    write_OLED_message(message,0,0);
    display_draw();
}
예제 #5
0
void display_message(int row, int col, char *message){

    int i = 0;
    int k;
    int j;
    int new_row = row;
    int column_ctr = 0;
    while(message[i]){
        
        char askey_index = message[i] - 0x20;

        for (k=0; k<5; k++){

            char askey_col = ASCII[askey_index][k];
            

            for(j = 7; j>=0; j--){
                display_pixel_set(new_row, (column_ctr + col), (askey_col&(1<<j)));
                new_row = new_row - 1;
            }
            new_row = row;
            column_ctr++;
        }

        i++;
    }
    display_draw();
}
예제 #6
0
int main ( void )
{
    /* Initialize all MPLAB Harmony modules, including application(s). */
 
    char message[100];
    SYS_Initialize ( NULL );
    //set up accelerometer
    acc_setup();
   //set up display
    display_init();
    display_clear();
    sprintf(message,"System Initialised!");
    write_string(message,0,0);
    display_draw();    
    while ( true )
    {
        /* Maintain state machines of all polled MPLAB Harmony modules. */
        SYS_Tasks ( );
        

    }

    /* Execution should not come here during normal operation */

    return ( EXIT_FAILURE );
}
예제 #7
0
파일: abc_embox.c 프로젝트: Julia117/embox
static void display_clean_sp(uint8_t x, uint8_t y) {
	size_t t, k;
	for (t = 0; t < 10; t++) {
		for (k = 0; k < 3; k++) {
			display_draw(x + t, y + k, 1, 8, &pict_buff0[0]);
		}
	}
	nxt_lcd_force_update();
}
예제 #8
0
파일: abc_embox.c 프로젝트: Julia117/embox
static void display_o(uint8_t x, uint8_t y) {
	display_draw(x, y, 1, 8, &pict_buff1[0]);
	display_draw(x + 8, y, 1, 8, &pict_buff2[0]);
	display_draw(x, y + 1, 1, 8, &pict_buff8[0]);
	display_draw(x + 8, y + 1, 1, 8, &pict_buff10[0]);
	display_draw(x, y + 2, 1, 8, &pict_buff3[0]);
	display_draw(x + 8, y + 2, 1, 8, &pict_buff4[0]);
	nxt_lcd_force_update();
}
예제 #9
0
파일: abc_embox.c 프로젝트: Julia117/embox
static void display_m(uint8_t x, uint8_t y) {
	display_draw(x, y, 1, 8, &pict_buff3[0]);
	display_draw(x + 8, y, 1, 8, &pict_buff5[0]);
	display_draw(x, y + 1, 1, 8, &pict_buff6[0]);
	display_draw(x + 8, y + 1, 1, 8, &pict_buff7[0]);
	display_draw(x, y + 2, 1, 8, &pict_buff6[0]);
	display_draw(x + 8, y + 2, 1, 8, &pict_buff7[0]);
	nxt_lcd_force_update();
}
예제 #10
0
void display_arrow(int x_val, int y_val){
    display_clear();
    //starts at center of board
    int row = 32;
    int col = 64;

    // scales the values to draw a line proportional to the values from accelerometer and still be able to fit on the screen
    int x_draw, y_draw;
    x_draw = x_val*SCALE;
    y_draw = y_val*SCALE;

    //determines direction to draw the line - up, down, left, or right
    int x_direction = 1, y_direction = 1;
    if (x_draw > 0){
        x_direction = -1;
    };
    if (y_draw > 0){
        y_direction = -1;
    };

    //take absolute value so that value will get smaller in while loop
    x_draw = abs(x_draw);
    y_draw = abs(y_draw);

    //will draw a line of pixels at a time, to a length proportional to the value from accelerometer
    int w;
    while(x_draw > 0){
        row = row + 1*x_direction;          //multiply by x_direction for line to be in the right direction
        for(w = 0; w < 5; w++){              // draws a thin line 5 pixels wide
           display_pixel_set(row, col+w, 1); //set the pixel value
        };
        x_draw = x_draw - 1;
    }

    //set the row back to the center of screen
    row = 32;
    int h;
    while(y_draw > 0){
        col = col + 1*y_direction;
        for(h = 0; h < 5; h++){
           display_pixel_set(row + h, col, 1); //set the pixel value
        };
        y_draw = y_draw - 1;
    }

    display_draw(); //draws the image
}
예제 #11
0
파일: display.c 프로젝트: mtl/tmk_keyboard
void display_init() {

//    u8g_InitSPI(
//        &u8g,
//        &u8g_dev_ssd1351_128x128_18bpp_sw_spi,
//        // sck, mosi, cs, a0 (C/D), reset
//        PN(1, 1), PN(1, 2), PN(1, 0), PN(0, 6), PN(0, 7)
//    );

    u8g_InitHWSPI(
        &u8g,
        &u8g_dev_ssd1351_128x128_18bpp_hw_spi,
        // cs, a0 (C/D), reset
        PN(1, 0), PN(0, 6), PN(0, 7)
    );

    display_draw( true );
}
예제 #12
0
파일: pic_accel.c 프로젝트: mjc401/ME433
void accelerometer_pixel_bars(void){
    short accels[3];
    int xpix,ypix;
    char x_acc_dir,y_acc_dir;
    unsigned char x_dir[20],y_dir[20];
    acc_read_register(OUT_X_L_A,(unsigned char *) accels, 6);
    xpix = accel_to_pixels(accels[0]);
    ypix = accel_to_pixels(accels[1]);
    x_acc_dir = accel_pixel_direction(xpix);
    y_acc_dir = accel_pixel_direction(ypix);
    sprintf(x_dir,"X-Acc = %c",x_acc_dir);
    sprintf(y_dir,"Y-Acc = %c",y_acc_dir);
    display_clear();
    write_OLED_message(x_dir,0,0);
    write_OLED_message(y_dir,10,0);
    accel_pixels(xpix,'x');
    accel_pixels(ypix,'y');
    display_draw();
}
예제 #13
0
void display_bars(int len, int dir){
    //0 for x dir, 1 for y dir
    int i;
    if (dir == 0){
        if (len > 0){
            if (len > 60){
                len = 60;
            }
            for(i = 0; i < abs(len); i++){
                display_pixel_set(32, (64+i), 1);
            }
        }
        else if (len < 0){
            if (len < -60){
                len = -60;
            }
            for(i = 0; i < abs(len); i++){
                display_pixel_set(32, (64-i), 1);
            }
        }    
    }
    if(dir == 1){
        if (len > 0){
            if (len > 25){
                len = 25;
            }
            for(i = 0; i < abs(len); i++){
                display_pixel_set((32+i), 64, 1);
            }
        }
        else if (len < 0){
            if (len < -25){
                len = -25;
            }
            for(i = 0; i < abs(len); i++){
                display_pixel_set((32-i), 64, 1);
            }
        }
    }
    display_draw();
}
예제 #14
0
int main() {

    BM_setup();

    display_clear();
    acc_write_register(0x00,0x04,(unsigned char *) buff,2);
    sprintf(message,"%d%d",buff[1],buff[2]);
    oledprint(1,10,message);
    display_draw();

//    while (1) {
//
//        display_clear();
//
//        acc_write_register(RDCVA, buff);
//
//        sprintf(buff,"Message: ",data);
//
//        oledprint(1,10,buff);
//        display_draw();
//    }
}
예제 #15
0
static void callback_display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    display_draw();
    glutSwapBuffers(); 
}
예제 #16
0
파일: graphics.c 프로젝트: justinzane/navit
void
graphics_redraw(struct container *co)
{
	int scale=transform_get_scale(co->trans);
	int i,slimit=255,tlimit=255,plimit=255;
	int bw[4],w[4],t[4];
	struct display_list **disp=co->disp;
	struct graphics *gra=co->gra;

#if 0
	printf("scale=%d center=0x%lx,0x%lx mercator scale=%f\n", scale, co->trans->center.x, co->trans->center.y, transform_scale(co->trans->center.y));
#endif
	
	display_free(co->disp, display_end);

	transform_setup_source_rect(co->trans);

	gra->draw_mode(gra, draw_mode_begin);
	for (i = 0 ; i < data_window_type_end; i++) {
		data_window_begin(co->data_window[i]);	
	}
	gra->gc_set_linewidth(gra->gc[GC_RAIL], 3);

	bw[0]=0;
	bw[1]=0;
	bw[2]=0;
	bw[3]=0;
	w[0]=1;
	w[1]=1;
	w[2]=1;
	w[3]=1;
	t[0]=0xf;
	t[1]=0xf;
	t[2]=0xf;
	t[3]=0xf;
	if (scale < 2) {
		tlimit=0xff;
		slimit=0xff;
		bw[0]=17;
		w[0]=15;
		bw[1]=19;
		w[1]=17;
		bw[2]=19;
		w[2]=17;
		bw[3]=21;
		w[3]=17;
	} else if (scale < 4) {
		tlimit=0xff;
		slimit=0xff;
		bw[0]=11;
		w[0]=9;
		bw[1]=13;
		w[1]=11;
		bw[2]=13;
		w[2]=11;
		bw[3]=15;
		w[3]=11;
	} else if (scale < 8) {
		tlimit=0xff;
		slimit=0xff;
		bw[0]=5;
		w[0]=3;
		bw[1]=11;
		w[1]=9;
		bw[2]=11;
		w[2]=9;
		bw[3]=13;
		w[3]=9;
		t[0]=0xa;
		t[1]=0xf;
	} else if (scale < 16) {
		tlimit=0xff;
		slimit=0xff;
		bw[1]=9;
		w[1]=7;
		bw[2]=9;
		w[2]=7;
		bw[3]=11;
		w[3]=7;
		t[0]=0x9;
		t[1]=0xe;
	} else if (scale < 32) {
		tlimit=0xff;
		slimit=0xff;
		bw[1]=5;
		w[1]=3;
		bw[2]=5;
		w[2]=3;
		bw[3]=5;
		w[3]=3;
		t[0]=0x8;
		t[1]=0xb;
	} else if (scale < 64) {
		tlimit=0xf;
		slimit=0x6;
		bw[1]=5;
		w[1]=3;
		bw[2]=5;
		w[2]=3;
		bw[3]=5;
		w[3]=3;
		t[0]=0x8;
		t[1]=0xa;
	} else if (scale < 128) {
		tlimit=0xc;
		slimit=0x6;
		plimit=0x1e;
		w[1]=3;
		w[2]=3;
		bw[3]=5;
		w[3]=3;
		t[0]=0x7;
		t[1]=0xa;
	} else if (scale < 256) {
		tlimit=0xb;
		slimit=0x5;
		plimit=0x1a;
		w[2]=3;
		bw[3]=5;
		w[3]=3;
		t[0]=0x7;
		t[1]=0x8;
	} else if (scale < 512) {
		tlimit=0x9;
		slimit=0x5;
		plimit=0x14;
		w[1]=0;
		w[2]=1;
		bw[3]=3;
		w[3]=1;
		t[0]=0x4;
		t[1]=0x7;
	} else if (scale < 1024) {
		tlimit=0x8;
		slimit=0x4;
		slimit=0x4;
		plimit=0x11;
		w[1]=0;
		w[2]=1;
		bw[3]=3;
		w[3]=1;
		t[0]=0x3;
		t[1]=0x5;
	} else if (scale < 2048) {
		tlimit=0x5;
		slimit=0x3;
		plimit=0x10;
		bw[3]=3;
		w[3]=1;
		t[0]=0x2;
		t[1]=0x4;
	} else if (scale < 4096) {
		bw[3]=3;
		w[3]=1;
		tlimit=0x4;
		slimit=0x2;
		plimit=0xf;
		t[0]=0x2;
		t[1]=0x3;
	} else if (scale < 8192) {
		bw[3]=3;
		w[3]=1;
		tlimit=0x3;
		slimit=0x2;
		plimit=0xf;
		t[0]=0x1;
		t[1]=0x2;
	} else {
		bw[3]=3;
		w[3]=1;
		tlimit=0x2;
		slimit=0x2;
		plimit=0xf;
		t[0]=0x1;
		t[1]=0x4;
	}
	gra->gc_set_linewidth(gra->gc[GC_STREET_SMALL], w[0]);
	gra->gc_set_linewidth(gra->gc[GC_STREET_NO_PASS], w[0]);
	gra->gc_set_linewidth(gra->gc[GC_STREET_SMALL_B], bw[0]);
	gra->gc_set_linewidth(gra->gc[GC_STREET_MID], w[1]);
	gra->gc_set_linewidth(gra->gc[GC_STREET_MID_B], bw[1]);
	gra->gc_set_linewidth(gra->gc[GC_STREET_BIG], w[2]);
	gra->gc_set_linewidth(gra->gc[GC_STREET_BIG_B], bw[2]);
	gra->gc_set_linewidth(gra->gc[GC_STREET_BIG2], w[3]);
	gra->gc_set_linewidth(gra->gc[GC_STREET_BIG2_B], bw[3]);
	gra->gc_set_linewidth(gra->gc[GC_STREET_ROUTE], w[3]+7+w[3]/2);

	profile_timer(NULL);
	graphics_draw(co->map_data, file_border_ply, co, display_rail, plimit, 48, poly_draw_block);
	graphics_draw(co->map_data, file_woodland_ply, co, display_wood, plimit, 48, poly_draw_block);
	graphics_draw(co->map_data, file_other_ply, co, display_other, plimit, 48, poly_draw_block);
	graphics_draw(co->map_data, file_town_twn, co, display_town, tlimit, 48, town_draw_block);
	graphics_draw(co->map_data, file_water_ply, co, display_water, plimit, 48, poly_draw_block);
	graphics_draw(co->map_data, file_sea_ply, co, display_sea, plimit, 48, poly_draw_block);
	/* todo height, tunnel, bridge, street_bti ??? */
#if 0
	graphics_draw(co->map_data, file_height_ply, co, display_other1, plimit, 48, poly_draw_block);
#endif
	if (scale < 256) {
		graphics_draw(co->map_data, file_rail_ply, co, display_rail, plimit, 48, poly_draw_block);
	}
	profile_timer("map_draw");
	plugin_call_draw(co);
	profile_timer("plugin");
#if 0
	draw_poly(map, &co->d_tunnel_ply, "Tunnel", 0, 11, plimit);
#endif
	graphics_draw(co->map_data, file_street_str, co, display_street, slimit, 7, street_draw_block);
  
	display_draw(disp[display_sea], gra, gra->gc[GC_WATER_FILL], NULL); 
	display_draw(disp[display_wood], gra, gra->gc[GC_WOOD], NULL); 
	display_draw(disp[display_other], gra, gra->gc[GC_TOWN_FILL], gra->gc[GC_TOWN_LINE]); 
	display_draw(disp[display_other1], gra, gra->gc[GC_BUILDING], NULL); 
	display_draw(disp[display_other2], gra, gra->gc[GC_BUILDING_2], NULL); 
	display_draw(disp[display_other3], gra, gra->gc[GC_PARK], NULL); 
	display_draw(disp[display_water], gra, gra->gc[GC_WATER_FILL], gra->gc[GC_WATER_LINE]); 
	display_draw(disp[display_rail], gra, gra->gc[GC_RAIL], NULL); 
	street_route_draw(co);
	display_draw(disp[display_street_route], gra, gra->gc[GC_STREET_ROUTE], NULL); 
	if (bw[0]) {
		display_draw(disp[display_street_no_pass], gra, gra->gc[GC_STREET_SMALL_B], NULL); 
		display_draw(disp[display_street], gra, gra->gc[GC_STREET_SMALL_B], NULL); 
	}
	if (bw[1]) 
		display_draw(disp[display_street1], gra, gra->gc[GC_STREET_MID_B], NULL); 
	if (bw[2])
		display_draw(disp[display_street2], gra, gra->gc[GC_STREET_BIG_B], NULL); 
	if (bw[3])
		display_draw(disp[display_street3], gra, gra->gc[GC_STREET_BIG2_B], NULL); 
	if (w[0]) {
		display_draw(disp[display_street_no_pass], gra, gra->gc[GC_STREET_NO_PASS], NULL); 
		display_draw(disp[display_street], gra, gra->gc[GC_STREET_SMALL], NULL); 
	}
	if (w[1]) 
		display_draw(disp[display_street1], gra, gra->gc[GC_STREET_MID], gra->gc[GC_BLACK]); 
	display_draw(disp[display_street2], gra, gra->gc[GC_STREET_BIG], gra->gc[GC_BLACK]); 
	display_draw(disp[display_street3], gra, gra->gc[GC_STREET_BIG2], gra->gc[GC_BLACK]); 
	if (w[3] > 1) 
		display_draw(disp[display_street3], gra, gra->gc[GC_STREET_BIG2_L], NULL); 

	display_draw(disp[display_poi], gra, gra->gc[GC_BLACK], NULL); 


	profile_timer("display_draw");

	if (scale < 2) {
		display_labels(disp[display_street], gra, gra->gc[GC_TEXT_FG], gra->gc[GC_TEXT_BG], gra->font[1]);
		display_labels(disp[display_street1], gra, gra->gc[GC_TEXT_FG], gra->gc[GC_TEXT_BG], gra->font[1]);
	}
	else {
		display_labels(disp[display_street], gra, gra->gc[GC_TEXT_FG], gra->gc[GC_TEXT_BG], gra->font[0]);
		display_labels(disp[display_street1], gra, gra->gc[GC_TEXT_FG], gra->gc[GC_TEXT_BG], gra->font[0]);
	}
	display_labels(disp[display_street2], gra, gra->gc[GC_TEXT_FG], gra->gc[GC_TEXT_BG], gra->font[0]);
	display_labels(disp[display_street3], gra, gra->gc[GC_TEXT_FG], gra->gc[GC_TEXT_BG], gra->font[0]);

	for (i = display_town+t[1] ; i < display_town+0x10 ; i++) 
		display_labels(disp[i], gra, gra->gc[GC_TEXT_FG], gra->gc[GC_TEXT_BG], gra->font[0]);
	for (i = display_town+t[0] ; i < display_town+t[1] ; i++) 
		display_labels(disp[i], gra, gra->gc[GC_TEXT_FG], gra->gc[GC_TEXT_BG], gra->font[1]);
	for (i = display_town ; i < display_town+t[0] ; i++) 
		display_labels(disp[i], gra, gra->gc[GC_TEXT_FG], gra->gc[GC_TEXT_BG], gra->font[2]);

	for (i = display_town ; i < display_town+0x10 ; i++) 
		display_draw(disp[i], gra, gra->gc[GC_BLACK], NULL); 
	display_draw(disp[display_bti], gra, gra->gc[GC_BLACK], NULL); 
	profile_timer("labels");
	gra->draw_mode(gra, draw_mode_end);
	for (i = 0 ; i < data_window_type_end; i++) {
		data_window_end(co->data_window[i]);	
	}
#if 0
	map_scrollbars_update(map);
#endif
}
예제 #17
0
파일: HW4.c 프로젝트: PrestonWang/HW4
int main() {

    // startup
    __builtin_disable_interrupts();

    // set the CP0 CONFIG register to indicate that
    // kseg0 is cacheable (0x3) or uncacheable (0x2)
    // see Chapter 2 "CPU for Devices with M4K Core"
    // of the PIC32 reference manual
    __builtin_mtc0(_CP0_CONFIG, _CP0_CONFIG_SELECT, 0xa4210583);

    // no cache on this chip!

    // 0 data RAM access wait states
    BMXCONbits.BMXWSDRM = 0x0;

    // enable multi vector interrupts
    INTCONbits.MVEC = 0x1;

    // disable JTAG to be able to use TDI, TDO, TCK, TMS as digital
    DDPCONbits.JTAGEN = 0;

    __builtin_enable_interrupts();

    // set up USER pin as input

    ANSELBbits.ANSB13 = 0;
    TRISBbits.TRISB13 = 1;
    INT4Rbits.INT4R = 0b0100;

    // set up LED1 pin as a digital output
    ANSELBbits.ANSB15 = 0;
    TRISBbits.TRISB15 = 0;
    LATBbits.LATB15 = 1;
    int d = 0;
    while(d < 2000000){
    d = d+1;
    }
    // initializing variables

    // lookup table for all of the ascii characters
    static const char ASCII[96][5] = {
    {0x00, 0x00, 0x00, 0x00, 0x00} // 20  (space)
    ,{0x00, 0x00, 0x5f, 0x00, 0x00} // 21 !
    ,{0x00, 0x07, 0x00, 0x07, 0x00} // 22 "
    ,{0x14, 0x7f, 0x14, 0x7f, 0x14} // 23 #
    ,{0x24, 0x2a, 0x7f, 0x2a, 0x12} // 24 $
    ,{0x23, 0x13, 0x08, 0x64, 0x62} // 25 %
    ,{0x36, 0x49, 0x55, 0x22, 0x50} // 26 &
    ,{0x00, 0x05, 0x03, 0x00, 0x00} // 27 '
    ,{0x00, 0x1c, 0x22, 0x41, 0x00} // 28 (
    ,{0x00, 0x41, 0x22, 0x1c, 0x00} // 29 )
    ,{0x14, 0x08, 0x3e, 0x08, 0x14} // 2a *
    ,{0x08, 0x08, 0x3e, 0x08, 0x08} // 2b +
    ,{0x00, 0x50, 0x30, 0x00, 0x00} // 2c ,
    ,{0x08, 0x08, 0x08, 0x08, 0x08} // 2d -
    ,{0x00, 0x60, 0x60, 0x00, 0x00} // 2e .
    ,{0x20, 0x10, 0x08, 0x04, 0x02} // 2f /
    ,{0x3e, 0x51, 0x49, 0x45, 0x3e} // 30 0
    ,{0x00, 0x42, 0x7f, 0x40, 0x00} // 31 1
    ,{0x42, 0x61, 0x51, 0x49, 0x46} // 32 2
    ,{0x21, 0x41, 0x45, 0x4b, 0x31} // 33 3
    ,{0x18, 0x14, 0x12, 0x7f, 0x10} // 34 4
    ,{0x27, 0x45, 0x45, 0x45, 0x39} // 35 5
    ,{0x3c, 0x4a, 0x49, 0x49, 0x30} // 36 6
    ,{0x01, 0x71, 0x09, 0x05, 0x03} // 37 7
    ,{0x36, 0x49, 0x49, 0x49, 0x36} // 38 8
    ,{0x06, 0x49, 0x49, 0x29, 0x1e} // 39 9
    ,{0x00, 0x36, 0x36, 0x00, 0x00} // 3a :
    ,{0x00, 0x56, 0x36, 0x00, 0x00} // 3b ;
    ,{0x08, 0x14, 0x22, 0x41, 0x00} // 3c <
    ,{0x14, 0x14, 0x14, 0x14, 0x14} // 3d =
    ,{0x00, 0x41, 0x22, 0x14, 0x08} // 3e >
    ,{0x02, 0x01, 0x51, 0x09, 0x06} // 3f ?
    ,{0x32, 0x49, 0x79, 0x41, 0x3e} // 40 @
    ,{0x7e, 0x11, 0x11, 0x11, 0x7e} // 41 A
    ,{0x7f, 0x49, 0x49, 0x49, 0x36} // 42 B
    ,{0x3e, 0x41, 0x41, 0x41, 0x22} // 43 C
    ,{0x7f, 0x41, 0x41, 0x22, 0x1c} // 44 D
    ,{0x7f, 0x49, 0x49, 0x49, 0x41} // 45 E
    ,{0x7f, 0x09, 0x09, 0x09, 0x01} // 46 F
    ,{0x3e, 0x41, 0x49, 0x49, 0x7a} // 47 G
    ,{0x7f, 0x08, 0x08, 0x08, 0x7f} // 48 H
    ,{0x00, 0x41, 0x7f, 0x41, 0x00} // 49 I
    ,{0x20, 0x40, 0x41, 0x3f, 0x01} // 4a J
    ,{0x7f, 0x08, 0x14, 0x22, 0x41} // 4b K
    ,{0x7f, 0x40, 0x40, 0x40, 0x40} // 4c L
    ,{0x7f, 0x02, 0x0c, 0x02, 0x7f} // 4d M
    ,{0x7f, 0x04, 0x08, 0x10, 0x7f} // 4e N
    ,{0x3e, 0x41, 0x41, 0x41, 0x3e} // 4f O
    ,{0x7f, 0x09, 0x09, 0x09, 0x06} // 50 P
    ,{0x3e, 0x41, 0x51, 0x21, 0x5e} // 51 Q
    ,{0x7f, 0x09, 0x19, 0x29, 0x46} // 52 R
    ,{0x46, 0x49, 0x49, 0x49, 0x31} // 53 S
    ,{0x01, 0x01, 0x7f, 0x01, 0x01} // 54 T
    ,{0x3f, 0x40, 0x40, 0x40, 0x3f} // 55 U
    ,{0x1f, 0x20, 0x40, 0x20, 0x1f} // 56 V
    ,{0x3f, 0x40, 0x38, 0x40, 0x3f} // 57 W
    ,{0x63, 0x14, 0x08, 0x14, 0x63} // 58 X
    ,{0x07, 0x08, 0x70, 0x08, 0x07} // 59 Y
    ,{0x61, 0x51, 0x49, 0x45, 0x43} // 5a Z
    ,{0x00, 0x7f, 0x41, 0x41, 0x00} // 5b [
    ,{0x02, 0x04, 0x08, 0x10, 0x20} // 5c ¥
    ,{0x00, 0x41, 0x41, 0x7f, 0x00} // 5d ]
    ,{0x04, 0x02, 0x01, 0x02, 0x04} // 5e ^
    ,{0x40, 0x40, 0x40, 0x40, 0x40} // 5f _
    ,{0x00, 0x01, 0x02, 0x04, 0x00} // 60 `
    ,{0x20, 0x54, 0x54, 0x54, 0x78} // 61 a
    ,{0x7f, 0x48, 0x44, 0x44, 0x38} // 62 b
    ,{0x38, 0x44, 0x44, 0x44, 0x20} // 63 c
    ,{0x38, 0x44, 0x44, 0x48, 0x7f} // 64 d
    ,{0x38, 0x54, 0x54, 0x54, 0x18} // 65 e
    ,{0x08, 0x7e, 0x09, 0x01, 0x02} // 66 f
    ,{0x0c, 0x52, 0x52, 0x52, 0x3e} // 67 g
    ,{0x7f, 0x08, 0x04, 0x04, 0x78} // 68 h
    ,{0x00, 0x44, 0x7d, 0x40, 0x00} // 69 i
    ,{0x20, 0x40, 0x44, 0x3d, 0x00} // 6a j
    ,{0x7f, 0x10, 0x28, 0x44, 0x00} // 6b k
    ,{0x00, 0x41, 0x7f, 0x40, 0x00} // 6c l
    ,{0x7c, 0x04, 0x18, 0x04, 0x78} // 6d m
    ,{0x7c, 0x08, 0x04, 0x04, 0x78} // 6e n
    ,{0x38, 0x44, 0x44, 0x44, 0x38} // 6f o
    ,{0x7c, 0x14, 0x14, 0x14, 0x08} // 70 p
    ,{0x08, 0x14, 0x14, 0x18, 0x7c} // 71 q
    ,{0x7c, 0x08, 0x04, 0x04, 0x08} // 72 r
    ,{0x48, 0x54, 0x54, 0x54, 0x20} // 73 s
    ,{0x04, 0x3f, 0x44, 0x40, 0x20} // 74 t
    ,{0x3c, 0x40, 0x40, 0x20, 0x7c} // 75 u
    ,{0x1c, 0x20, 0x40, 0x20, 0x1c} // 76 v
    ,{0x3c, 0x40, 0x30, 0x40, 0x3c} // 77 w
    ,{0x44, 0x28, 0x10, 0x28, 0x44} // 78 x
    ,{0x0c, 0x50, 0x50, 0x50, 0x3c} // 79 y
    ,{0x44, 0x64, 0x54, 0x4c, 0x44} // 7a z
    ,{0x00, 0x08, 0x36, 0x41, 0x00} // 7b {
    ,{0x00, 0x00, 0x7f, 0x00, 0x00} // 7c |
    ,{0x00, 0x41, 0x36, 0x08, 0x00} // 7d }
    ,{0x10, 0x08, 0x08, 0x10, 0x08} // 7e ?
    ,{0x00, 0x06, 0x09, 0x09, 0x06} // 7f ?
    }; // end char ASCII[96][5]

    // Initializing Display

    i2c_master_setup();
    display_init();
    char a;
    char message[10];
    int m = 0;
    int i;
    int j;
    int row;
    int col;
    // main loop
    while (1) {
    row = 32;
    col = 28;
    sprintf(message,"Hello world 1337!");
    while(message[m]){
        for(j = 0; j<= 4; j = j+1,col = col + 1){
            a = ASCII[message[m] - 0x20][j];
            for(i = 0; i <= 7; i = i+1)
            {
            display_pixel_set(row -i,col,(a << i)&0x80);
            }
        }
        m = m+1;
    }
    display_draw();
    m = 0;

}
}
예제 #18
0
파일: pic_code.c 프로젝트: pg8/ME433
int main() {

    int potValue;
    int timerResets=0;
    // startup
    startup();


T2CONbits.TCKPS = 2; // Timer2 prescaler N=4 (1:4)
PR2 = 19999; // period = (PR2+1) * N * 12.5 ns = 100 us, 10 kHz
TMR2 = 0; // initial TMR2 count is 0
OC1CONbits.OCM = 0b110; // PWM mode without fault pin; other OC1CON bits are defaults
OC1RS = 5000; // duty cycle = OC1RS/(PR2+1) = 25%
OC1R = 5000; // initialize before turning OC1 on; afterward it is read-only
T2CONbits.ON = 1; // turn on Timer2
OC1CONbits.ON = 1; // turn on OC1


    // set up USER pin as input
ANSELBbits.ANSB13 = 0; // 0 for digital, 1 for analog

    // set up LED1 pin as a digital output
ANSELBbits.ANSB15 = 0; // 0 for digital, 1 for analog

TRISBbits.TRISB15 = 0;

    // set up LED2 as OC1 using Timer2 at 1kHz
//RPB7Rbits.RPB7R = 0b0101; // set B15 to OC1
TRISBbits.TRISB7 = 0;
LATBbits.LATB7=0;

//LATBbits.LATB15=1;

    // set up A0 as AN0
    ANSELAbits.ANSA0 = 1;
    AD1CON3bits.ADCS = 3;
    AD1CHSbits.CH0SA = 0;
    AD1CON1bits.ADON = 1;

    int counter = 0;
    int user = 1;


/* /////////Testing section, old code///////////
    display_init();
    drawChar(72-0x20,45,50);
    drawChar(73-0x20,50,50);
    display_draw();
*/


 /*   /////// Write to LCD
    display_init();
    int k=0;
    int L=0;
    int charCurrent;
    int xIndex = 28;
    int yIndex = 32;
    char message[50];
    sprintf(message,"Hello world 1337!");

    while(L==0){
        charCurrent = (int)message[k];
        if(charCurrent==0){
            L=1;
        }
        else{
            drawChar(charCurrent - 0x20,xIndex, yIndex);
            xIndex+=6;
            k+=1;
        }
    }
    display_draw();

*/




    int a;
    int b;
    int aa;
    int bb;
    int c;
    int d;

    // set up power supply to LCD as digital output
    _CP0_SET_COUNT(0);
    while(_CP0_GET_COUNT()<4000000){

    }
    LATBbits.LATB15=1;

    display_init();


    int charCurrent;


    acc_setup();



    while (1) {

        display_clear();

    int xIndex = 10;
    int yIndex = 32;

        int k=0;
        int L=0;

    char message[500];


    short accels[3]; // accelerations for the 3 axes

    short mags[3]; // magnetometer readings for the 3 axes

    short temp;

    // read the accelerometer from all three axes

    // the accelerometer and the pic32 are both little endian by default (the lowest address has the LSB)

    // the accelerations are 16-bit twos compliment numbers, the same as a short

    acc_read_register(OUT_X_L_A, (unsigned char *) accels, 6);

    // need to read all 6 bytes in one transaction to get an update.

    acc_read_register(OUT_X_L_M, (unsigned char *) mags, 6);

    // read the temperature data. Its a right justified 12 bit two's compliment number

    acc_read_register(TEMP_OUT_L, (unsigned char *) &temp, 2);

    /*
    /////// Write to LCD
    sprintf(message,"%d %d %d                   ",accels[0], accels[1],accels[2]);
    L=0;
    
    while(message[k]){
            drawChar(message[k] - 0x20,xIndex, yIndex);
            xIndex+=6;
            k+=1;
        //}
    } */

    a=accels[0]/500;
    b=accels[1]/1000;
    display_pixel_set(31,64,1);
    display_pixel_set(32,64,1);
    display_pixel_set(33,64,1);
    display_pixel_set(32,63,1);
    display_pixel_set(32,65,1);
    if(a<0){
        c=-a;
        for(aa=0;aa<c;aa++){
            display_pixel_set(31,64-aa,1);
            display_pixel_set(32,64-aa,1);
            display_pixel_set(33,64-aa,1);
        }
    }
    if(a>=0){
        for(aa=0;aa<a;aa++){
            display_pixel_set(31,aa+64,1);
            display_pixel_set(32,aa+64,1);
            display_pixel_set(33,aa+64,1);
        }
    }
    if(b<0){
        d=-b;
        for(bb=0;bb<d;bb++){
            display_pixel_set(32-bb,63,1);
            display_pixel_set(32-bb,64,1);
            display_pixel_set(32-bb,65,1);
        }
    }
    if(b>=0){
        for(bb=0;bb<b;bb++){
            display_pixel_set(32+bb,63,1);
            display_pixel_set(32+bb,64,1);
            display_pixel_set(32+bb,65,1);
        }
    }




    display_draw();
    }
}
예제 #19
0
파일: app.c 프로젝트: mjc401/ME433
void APP_Tasks (void )
{
    unsigned char print[26];
    int jj = 0,row;
    short accels[3];
    /* Check if device is configured.  See if it is configured with correct
     * configuration value  */

    switch(appData.state)
    {
        case APP_STATE_INIT:

            /* Open the device layer */
            appData.usbDevHandle = USB_DEVICE_Open( USB_DEVICE_INDEX_0, DRV_IO_INTENT_READWRITE );

            if(appData.usbDevHandle != USB_DEVICE_HANDLE_INVALID)
            {
                /* Register a callback with device layer to get event notification (for end point 0) */
                USB_DEVICE_EventHandlerSet(appData.usbDevHandle, APP_USBDeviceEventHandler, 0);

                appData.state = APP_STATE_WAIT_FOR_CONFIGURATION;
            }
            else
            {
                /* The Device Layer is not ready to be opened. We should try
                 * again later. */
            }

            break;

        case APP_STATE_WAIT_FOR_CONFIGURATION:

            if(appData.deviceConfigured == true)
            {
                /* Device is ready to run the main task */
                appData.hidDataReceived = false;
                appData.hidDataTransmitted = true;
                appData.state = APP_STATE_MAIN_TASK;

                /* Place a new read request. */
                USB_DEVICE_HID_ReportReceive (USB_DEVICE_HID_INDEX_0,
                        &appData.rxTransferHandle, appData.receiveDataBuffer, 64);
            }
            break;

        case APP_STATE_MAIN_TASK:

            if(!appData.deviceConfigured)
            {
                /* Device is not configured */
                appData.state = APP_STATE_WAIT_FOR_CONFIGURATION;
            }
            else if( appData.hidDataReceived )
            {
                /* Look at the data the host sent, to see what
                 * kind of application specific command it sent. */

                switch(appData.receiveDataBuffer[0])
                {
                    case 0x1:
                        /* Toggle on board LED1 to LED2. */
                        BSP_LEDToggle( APP_USB_LED_1 );
                        BSP_LEDToggle( APP_USB_LED_2 );

                        memcpy(print,&appData.receiveDataBuffer[2],25);
                        print[26] = '\0';

                        display_clear();
                        write_OLED_message(print,appData.receiveDataBuffer[1],0);
                        display_draw();

                        appData.hidDataReceived = false;

                        /* Place a new read request. */
                        USB_DEVICE_HID_ReportReceive (USB_DEVICE_HID_INDEX_0,
                                &appData.rxTransferHandle, appData.receiveDataBuffer, 64 );
                        _CP0_SET_COUNT(0);

                        break;

                    case 0x2:

                        if(appData.hidDataTransmitted)
                        {
                            /* Echo back to the host PC the command we are fulfilling in
                             * the first byte.  In this case, the Get Push-button State
                             * command. */
                             BSP_LEDToggle( APP_USB_LED_1 );
                             BSP_LEDToggle( APP_USB_LED_2 );
   
                            if(_CP0_GET_COUNT() > 200000){
                                appData.transmitDataBuffer[0] = 1;
                                acc_read_register(OUT_X_L_A,(unsigned char *) accels, 6);
                                appData.transmitDataBuffer[1] = accels[0] >> 8;
                                appData.transmitDataBuffer[2] = accels[0];
                                appData.transmitDataBuffer[3] = accels[1] >> 8;
                                appData.transmitDataBuffer[4] = accels[1];
                                appData.transmitDataBuffer[5] = accels[2] >> 8;
                                appData.transmitDataBuffer[6] = accels[2];
                                 _CP0_SET_COUNT(0);
                            }
                            else{
                                appData.transmitDataBuffer[0] = 0;
                            }
//                            appData.transmitDataBuffer[0] = 0x81;
//
//                            if( BSP_SwitchStateGet(APP_USB_SWITCH_1) == BSP_SWITCH_STATE_PRESSED )
//                            {
//                                appData.transmitDataBuffer[1] = 0x00;
//                            }
//                            else
//                            {
//                                appData.transmitDataBuffer[1] = 0x01;
//                            }

                            appData.hidDataTransmitted = false;

                            /* Prepare the USB module to send the data packet to the host */
                            USB_DEVICE_HID_ReportSend (USB_DEVICE_HID_INDEX_0,
                                    &appData.txTransferHandle, appData.transmitDataBuffer, 64 );

                            appData.hidDataReceived = false;

                            /* Place a new read request. */
                            USB_DEVICE_HID_ReportReceive (USB_DEVICE_HID_INDEX_0,
                                    &appData.rxTransferHandle, appData.receiveDataBuffer, 64 );
                        }
                        break;

                    default:

                        appData.hidDataReceived = false;

                        /* Place a new read request. */
                        USB_DEVICE_HID_ReportReceive (USB_DEVICE_HID_INDEX_0,
                                &appData.rxTransferHandle, appData.receiveDataBuffer, 64 );
                        break;
                }
예제 #20
0
int main() {
    // startup FROM HW1
    __builtin_disable_interrupts();
    __builtin_mtc0(_CP0_CONFIG, _CP0_CONFIG_SELECT, 0xa4210583);
    BMXCONbits.BMXWSDRM = 0x0;
    INTCONbits.MVEC = 0x1;
    DDPCONbits.JTAGEN = 0;
    __builtin_enable_interrupts();
    ANSELBbits.ANSB13 = 0; //Make B13 Digital
    TRISBbits.TRISB7 = 0;
    RPB15Rbits.RPB15R = 0b0101; //Set B15 as OC1
    T2CONbits.TCKPS = 0; //Prescalar = 1
    PR2 = 39999; //Max counter value
    TMR2 = 0; // Initialize timer 2
    OC1CONbits.OCM = 0b110; //Without failsafe
    OC1RS = 2000; //Duts cycle is 5%
    OC1R = 2000; //Initial duty cycle is 5%
    T2CONbits.ON = 1; //turns timer on
    OC1CONbits.ON = 1; //Turns output control on
    ANSELAbits.ANSA0 = 1;
    AD1CON3bits.ADCS = 3;
    AD1CHSbits.CH0SA = 0;
    AD1CON1bits.ADON = 1;

    display_init();

    while (1) {
        _CP0_SET_COUNT(0); // set core timer to 0, remember it counts at half the CPU clock
        LATBINV = 0b10000000; // invert a pin B7 (LED1)
        while (_CP0_GET_COUNT() < 10000000) {
            int val;
            val = readADC();
            OC1RS = val * 39; //comes out to about 39
            if (PORTBbits.RB13 == 1) {
            } else {
                LATBINV = 0b10000000; //Invert LED1
            }
        }
        //END STARTUP FROM HW1

        display_clear();

        char MessageLetters[17]; //= 'Hello world 1337!';
        sprintf(MessageLetters, "Hello world 1337!");
        int ii = 0;
        int currentVal;

        int message[17];
        while (MessageLetters[ii]) {
            currentVal = MessageLetters[ii];
            if (currentVal - 32 >= 0) {
                message[ii] = currentVal - 32;
            }
            ii++;
        }
        
        int StringCount;

        int colLCD; //Create column location on LCD
        int rowLCD; //Create row location on LCD

        for (StringCount = 0; StringCount < 20; StringCount++) {
            for (colLCD = 1; colLCD < 6; colLCD++) { //Cycle through column of array
                for (rowLCD = 1; rowLCD < 9; rowLCD++) { //Cycle through row of array
                    display_pixel_set(rowLCD + 32, colLCD + 6 * StringCount + 28, getBit(message[StringCount], rowLCD - 1, colLCD - 1)); //At this specific (row, col) of screen, turn LCD on (1) or off (0) based on array value

                }

            }
        }


        display_draw(); //Commit to LCD screen once all positions defined

    }
}
예제 #21
0
int main ( void )
{
    /* Initialize all MPLAB Harmony modules, including application(s). */
    SYS_Initialize ( NULL );
    // string used for OLED
    char str[200];

    ANSELBbits.ANSB13 = 0; // make analog input digital
    U1RXRbits.U1RXR = 0b0000; // set U1RX to pin A2
    RPB15Rbits.RPB15R = 0b0101; // set B15 to U1TX

    TRISBbits.TRISB13 = 1;     // set up USER pin as input
    TRISBbits.TRISB7 = 0;    // set up LED1 pin as a digital output

    APP_USBDeviceEventHandler();
    
    __builtin_disable_interrupts();

    // set the CP0 CONFIG register to indicate that
    // kseg0 is cacheable (0x3) or uncacheable (0x2)
    // see Chapter 2 "CPU for Devices with M4K Core"
    // of the PIC32 reference manual
    __builtin_mtc0(_CP0_CONFIG, _CP0_CONFIG_SELECT, 0xa4210583);

    // no cache on this chip!

    // 0 data RAM access wait states
    BMXCONbits.BMXWSDRM = 0x0;

    // enable multi vector interrupts
    INTCONbits.MVEC = 0x1;

    // disable JTAG to be able to use TDI, TDO, TCK, TMS as digital
    DDPCONbits.JTAGEN = 0;

     // set up accelerometer
    acc_setup();

    __builtin_enable_interrupts();

    short accels[3];    // accelerations for the 3 axes
    short mags[3];      // magnetometer readings for the 3 axes
    short temp;         // temperature

    display_init();

    while ( true )
    {
        /* Maintain state machines of all polled MPLAB Harmony modules. */
                // read the accelerometer from all three axes
        // the accelerometer and the pic32 are both little endian by default (the lowest address has the LSB)
        // the accelerations are 16-bit twos compliment numbers, the same as a short
        acc_read_register(OUT_X_L_A, (unsigned char *) accels, 6);
        // need to read all 6 bytes in one transaction to get an update.
        acc_read_register(OUT_X_L_M, (unsigned char *) mags, 6);

        // read the temperature data. Its a right justified 12 bit two's compliment number
        acc_read_register(TEMP_OUT_L, (unsigned char *) &temp, 2);


        display_clear();
//      sprintf(str, "Hello world %d!", accels);

        int x_acc = accels[0]*64/16000;
        int y_acc = accels[1]*32/16000;
        int xxx,yyy;

        if (x_acc>=0){
            if(x_acc>64) x_acc=64;
            for (xxx=0;xxx<x_acc;xxx++){
                display_pixel_set(31,64-xxx,1);
                display_pixel_set(32,64-xxx,1);
                display_pixel_set(33,64-xxx,1);
            }
        }
        else{
            if(x_acc<-64) x_acc=-64;
            for (xxx=0;xxx>x_acc;xxx--){
                display_pixel_set(31,64-xxx,1);
                display_pixel_set(32,64-xxx,1);
                display_pixel_set(33,64-xxx,1);
            }
        }

        if (y_acc>=0){
            if(y_acc>32) y_acc=32;
            for (yyy=0;yyy<y_acc;yyy++){
                display_pixel_set(32-yyy,63,1);
                display_pixel_set(32-yyy,64,1);
                display_pixel_set(32-yyy,65,1);
            }
        }
        else{
            if(y_acc<-32) y_acc=-32;
            for (yyy=0;yyy>y_acc;yyy--){
                display_pixel_set(32-yyy,63,1);
                display_pixel_set(32-yyy,64,1);
                display_pixel_set(32-yyy,65,1);
            }
        }

        display_draw();

        SYS_Tasks ( );

    }

    /* Execution should not come here during normal operation */

    return ( EXIT_FAILURE );
}
예제 #22
0
int main(void) {
    
//Startup
    __builtin_disable_interrupts();

    // set the CP0 CONFIG register to indicate that
    // kseg0 is cacheable (0x3) or uncacheable (0x2)
    // see Chapter 2 "CPU for Devices with M4K Core"
    // of the PIC32 reference manual
    __builtin_mtc0(_CP0_CONFIG, _CP0_CONFIG_SELECT, 0xa4210583);

    // no cache on this chip!

    // 0 data RAM access wait states
    BMXCONbits.BMXWSDRM = 0x0;

    // enable multi vector interrupts
    INTCONbits.MVEC = 0x1;

    // disable JTAG to be able to use TDI, TDO, TCK, TMS as digital
    DDPCONbits.JTAGEN = 0;

    __builtin_enable_interrupts();

ANSELBbits.ANSB13 = 0; // 0 for digital, 1 for analog
ANSELBbits.ANSB15 = 0; // 0 for digital, 1 for analog

    T2CONbits.TCKPS = 0;	//Setting prescaler to 1 (0 corresponds to 1)
    PR2 = 39999;            //Setting PR for timer 2 to 39999
    TMR2 = 0;				//Setting Timer 2 to 0
    OC1CONbits.OCTSEL = 0;	//Telling OC1 to use timer 2
    OC1CONbits.OCM = 0b110;	//Telling OC1 to use PWM without the fault
    OC1RS = 20000;			//Setting initial duty cycle to 20000/(39999+1)*100% = 50%
    OC1R = 20000;			//Updating duty cycles to 20000/(39999+1)*100% = 50%
    T2CONbits.ON = 1;		//turn on timer
    OC1CONbits.ON = 1;		//turn on OC code

// set up USER pin as input
    TRISBbits.TRISB13 = 1; // set pin B13 to be digital INPUT
    // U1RXRbits.U1RXR = 0b0011; // set U1RX to pin B13 (Input pin from User button)

// set up LED1 pin as a digital output
    TRISBbits.TRISB7 = 0; // set pin B7 to be digital OUTPUT
    // LATBbits.LATB7 = 1;
    // RPB7Rbits.RPB7R = 0b0001; //set B7 to U1TX (Output pin for LED1)
    
// set up LED2 as OC1 using Timer2 at 1kHz
    // TRISBbits.TRISB15 = 0; // set B15 to digital OUTPUT
    RPB15Rbits.RPB15R = 0b0101; // set B15 to U1TX (Output pin for OC1)

// set up A0 as AN0
    ANSELAbits.ANSA0 = 1;
    AD1CON3bits.ADCS = 3;
    AD1CHSbits.CH0SA = 0;
    AD1CON1bits.ADON = 1;
    
// Accelerometer
    acc_setup();
    short accels[3]; // accelerations for the 3 axes
    short mags[3]; // magnetometer readings for the 3 axes
    short temp;

// Display
    display_init();
    
    /*int number = 1337;
    sprintf(buffer,"Hello World %d!", number);
    display_write(28,32,buffer);
    */
    /*                           
    for (ii = 0; ii < 128; ii++){       // Draw a line from position (x,y) = (0,15) to (127,15)
    display_pixel_set(15,ii,1);
    display_draw();
    }*/
    
    
    while (1){
     // invert pin every 0.5s, set PWM duty cycle % to the pot voltage output %
        
        _CP0_SET_COUNT(0);
        LATBINV = 0b10000000;
        
            while(_CP0_GET_COUNT()<10000000){
                OC1RS = readADC()*(PR2+1)/1023; // delay for 10M core ticks, 0.5s
                if (PORTBbits.RB13 == 1){
                    ;// nothing
                }
                else{
                    LATBINV = 0b10000000;
                }
            }
        // read the accelerometer from all three axes
        // the accelerometer and the pic32 are both little endian by default (the lowest address has the LSB)
        // the accelerations are 16-bit twos compliment numbers, the same as a short
        acc_read_register(OUT_X_L_A, (unsigned char *) accels, 6);
        // need to read all 6 bytes in one transaction to get an update.
        acc_read_register(OUT_X_L_M, (unsigned char *) mags, 6);
        // read the temperature data. Its a right justified 12 bit two's compliment number
        acc_read_register(TEMP_OUT_L, (unsigned char *) &temp, 2);
        
        display_clear();
        
        sprintf(buffer1, "(ax, ay, az)");
        display_write(0, 0, buffer1);
        sprintf(buffer2, "(%d, %d, %d)", accels[0], accels[1], accels[2]);
        display_write(0, 48, buffer2);
        sprintf(buffer, "Derek Oung");
        display_write(0, 56, buffer);
        
        
        
        if (accels[0]>0 && accels[1]>0){
            x_line_point = (float)((float)accels[0]/16000*64) + 64;
            y_line_point = (float)((float)accels[1]/16000*32) + 32;
            /*
            while (i<x_line_point){
                display_pixel_set(32,i,1);
                i++;
            }
            */
                
                for (i=64;i<x_line_point;i++){
                    display_pixel_set(31, i, 1);
                    display_pixel_set(32, i, 1);
                    display_pixel_set(33, i, 1);
                    }
                for (j=32;j<y_line_point;j++){
                    display_pixel_set(j, 63, 1);
                    display_pixel_set(j, 64, 1);
                    display_pixel_set(j, 65, 1);
                }
        }
        else if (accels[0]>0 && accels[1]<0){
            x_line_point = (float)((float)accels[0]/16000*64) + 64;
            y_line_point = (float)((float)accels[1]/16000*32) + 32;
                for (i=64;i<x_line_point;i++){
                    display_pixel_set(31, i, 1);
                    display_pixel_set(32, i, 1);
                    display_pixel_set(33, i, 1);
                    }

                for (j=32;j>y_line_point;j--){
                    display_pixel_set(j, 63, 1);
                    display_pixel_set(j, 64, 1);
                    display_pixel_set(j, 65, 1);
                }
        }
        else if (accels[0]<0 && accels[1]>0){
            x_line_point = (float)((float)accels[0]/16000*64) + 64;
            y_line_point = (float)((float)accels[1]/16000*32) + 32;
                for (i=64;i>x_line_point;i--){
                    display_pixel_set(31, i, 1);
                    display_pixel_set(32, i, 1);
                    display_pixel_set(33, i, 1);
                    }

                for (j=32;j<y_line_point;j++){
                    display_pixel_set(j, 63, 1);
                    display_pixel_set(j, 64, 1);
                    display_pixel_set(j, 65, 1);
                }
        }
        else if (accels[0]<0 && accels[1]<0){
            x_line_point = (float)((float)accels[0]/16000*64) + 64;
            y_line_point = (float)((float)accels[1]/16000*32) + 32;
                for (i=64;i>x_line_point;i--){
                    display_pixel_set(31, i, 1);
                    display_pixel_set(32, i, 1);
                    display_pixel_set(33, i, 1);
                    }

                for (j=32;j>y_line_point;j--){
                    display_pixel_set(j, 63, 1);
                    display_pixel_set(j, 64, 1);
                    display_pixel_set(j, 65, 1);
                }
        }
        display_pixel_set(31,63,1);
        display_pixel_set(31,64,1);
        display_pixel_set(31,65,1);
        display_pixel_set(32,63,1);
        display_pixel_set(32,64,1);
        display_pixel_set(32,65,1);
        display_pixel_set(33,63,1);
        display_pixel_set(33,64,1);
        display_pixel_set(33,65,1);
        display_draw();
        
        
        }

}
예제 #23
0
파일: HW5.c 프로젝트: shn1988110/HW5
int main ()
{
    
    __builtin_disable_interrupts();

// set the CP0 CONFIG register to indicate that
// kseg0 is cacheable (0x3) or uncacheable (0x2)
// see Chapter 2 "CPU for Devices with M4K Core"
// of the PIC32 reference manual
__builtin_mtc0(_CP0_CONFIG, _CP0_CONFIG_SELECT, 0xa4210583);

// no cache on this chip!

// 0 data RAM access wait states
BMXCONbits.BMXWSDRM = 0x0;

// enable multi vector interrupts
INTCONbits.MVEC = 0x1;

// disable JTAG to be able to use TDI, TDO, TCK, TMS as digital
DDPCONbits.JTAGEN = 0;

__builtin_enable_interrupts();


TRISBbits.TRISB7 = 0;       // set up LED1 pin as a digital output
//    int i,a;
//    display_init();
//    for (i = 0; i<10; ++i)
//    {
//        a = 30+i;
//        display_pixel_set(15,a,1);
//        display_draw();
//    }
    char input[100]; 
    int i=0;
    short accels[3]; // accelerations for the 3 axes
    short mags[3]; // magnetometer readings for the 3 axes
    short temp; 
    
    acc_setup();    //initialize accelerometer
	display_init(); //initialize LED screen
    

    
    float xg, yg, zg;

    
    while(1)
    {
    start_position[0] = 0;
    start_position[1] = 0;
    center_position[0] = 32;
    center_position[1] = 64;
    acc_read_register(OUT_X_L_A, (unsigned char *) accels, 6);
    acc_read_register(OUT_X_L_M, (unsigned char *) mags, 6);
    acc_read_register(TEMP_OUT_L, (unsigned char *) &temp, 2);
    
    xg = (float) accels[0]/16000;
    yg = (float) accels[1]/16000;
    zg = (float) accels[2]/16000;
    
    sprintf(input,"x: %.2f y: %.2f z: %.2f ", xg,yg,zg);
    display_reset();
    display_draw();
    display_ggraph(xg,yg);
    while(input[i])
    {

        display_message(input[i]);
        i++;
        start_position[1] = start_position[1]+5;
//        if(start_position[1]+5>128)
//        {start_position[0]+1;}
//        else
//        {start_position[1] = start_position[1]+5;}
    }
    i = 0;
    display_draw();
    _CP0_SET_COUNT(0);
    while(_CP0_GET_COUNT()<5000000)
    {;}
    
    }
	return (0);
}
예제 #24
0
파일: app.c 프로젝트: neslerc/Homework2
void APP_Tasks (void )
{
    char message[25];
    char inputfrompc[25];
    int i;
    short accels[3]; // accelerations for the 3 axes
    short accelsMAF;
    short accelsFIR;
    int buf1=0;
    int buf2=0;
    int buf3=0;
    int buf4=0;
    int buf5=0;
    //bn*1000 for FIR
    float b1=.0088;
    float b2=.0479;
    float b3=.1640;
    float b4=.2793;
    float b5=.2793;
    float b6=.1640;
    float b7=.0479;
    float b8=.0088;

    int FIRbuf1=0;
    int FIRbuf2=0;
    int FIRbuf3=0;
    int FIRbuf4=0;
    int FIRbuf5=0;
    int FIRbuf6=0;
    int FIRbuf7=0;
    int FIRbuf8=0;


    //sprintf(message,"Hello!");
    //use_display(20,20,message);
    //display_draw();
    /* Check if device is configured.  See if it is configured with correct
     * configuration value  */

    switch(appData.state)
    {
        case APP_STATE_INIT:

            /* Open the device layer */
            appData.usbDevHandle = USB_DEVICE_Open( USB_DEVICE_INDEX_0, DRV_IO_INTENT_READWRITE );

            if(appData.usbDevHandle != USB_DEVICE_HANDLE_INVALID)
            {
                /* Register a callback with device layer to get event notification (for end point 0) */
                USB_DEVICE_EventHandlerSet(appData.usbDevHandle, APP_USBDeviceEventHandler, 0);

                appData.state = APP_STATE_WAIT_FOR_CONFIGURATION;
            }
            else
            {
                /* The Device Layer is not ready to be opened. We should try
                 * again later. */
            }

            break;

        case APP_STATE_WAIT_FOR_CONFIGURATION:

            if(appData.deviceConfigured == true)
            {
                /* Device is ready to run the main task */
                appData.hidDataReceived = false;
                appData.hidDataTransmitted = true;
                appData.state = APP_STATE_MAIN_TASK;

                /* Place a new read request. */
                USB_DEVICE_HID_ReportReceive (USB_DEVICE_HID_INDEX_0,
                        &appData.rxTransferHandle, appData.receiveDataBuffer, 64);
            }
            break;

        case APP_STATE_MAIN_TASK:

            if(!appData.deviceConfigured)
            {
                /* Device is not configured */
                appData.state = APP_STATE_WAIT_FOR_CONFIGURATION;
            }
            else if( appData.hidDataReceived )
            {
                /* Look at the data the host sent, to see what
                 * kind of application specific command it sent. */

                switch(appData.receiveDataBuffer[0])
                {
                    case 0x80:
                        /* Toggle on board LED1 to LED2. */
                        BSP_LEDToggle( APP_USB_LED_1 );
                        BSP_LEDToggle( APP_USB_LED_2 );
                        
                        for (i=0; i<8; i++){
                            inputfrompc[i] = appData.receiveDataBuffer[i+1];
                        }
                        use_display(20,20,inputfrompc);
                        display_draw();
                        appData.hidDataReceived = false;

                        /* Place a new read request. */
                        USB_DEVICE_HID_ReportReceive (USB_DEVICE_HID_INDEX_0,
                                &appData.rxTransferHandle, appData.receiveDataBuffer, 64 );

                        break;

                    case 0x81:

                        if(appData.hidDataTransmitted)
                        {
                            /* Echo back to the host PC the command we are fulfilling in
                             * the first byte.  In this case, the Get Push-button State
                             * command. */

                            appData.transmitDataBuffer[0] = 0x81;

                            acc_read_register(OUT_X_L_A, (unsigned char *) accels, 6);
                            sprintf(message,"Z: %d",accels[0]);
                            use_display(10,10,message);
                            display_draw();
                            if(_CP0_GET_COUNT()>800000){
                                appData.transmitDataBuffer[1] = 1;
                                appData.transmitDataBuffer[2] = accels[0]>>8;
                                appData.transmitDataBuffer[3] = accels[0]&0xFF;

                                //use MAF buffer values to calculate accelsMAF
                                accelsMAF = ((buf1+buf2+buf3+buf4+buf5+accels[0])/6);

                                //change MAF buffer values
                                buf5=buf4;
                                buf4=buf3;
                                buf3=buf2;
                                buf2=buf1;
                                buf1=accels[0];



                                //change FIR buffer values
                                FIRbuf8=FIRbuf7;
                                FIRbuf7=FIRbuf6;
                                FIRbuf6=FIRbuf5;
                                FIRbuf5=FIRbuf4;
                                FIRbuf4=FIRbuf3;
                                FIRbuf3=FIRbuf2;
                                FIRbuf2=FIRbuf1;
                                FIRbuf1=accels[0];
                                //FIR Filtering calculations
                                accelsFIR = (b1*FIRbuf1)+(b2*FIRbuf2)+(b3*FIRbuf3)+(b4*FIRbuf4)+(b5*FIRbuf5)+(b6*FIRbuf6)+(b7*FIRbuf7)+(b8*FIRbuf8);

                                appData.transmitDataBuffer[4] = accelsMAF>>8;
                                appData.transmitDataBuffer[5] = accelsMAF&0xFF;
                                appData.transmitDataBuffer[6] = accelsFIR>>8;
                                appData.transmitDataBuffer[7] = accelsFIR&0xFF;
                                _CP0_SET_COUNT(0);

                            }
                            else{appData.transmitDataBuffer[1]=0;}


                            

                            appData.hidDataTransmitted = false;

                            /* Prepare the USB module to send the data packet to the host */
                            USB_DEVICE_HID_ReportSend (USB_DEVICE_HID_INDEX_0,
                                    &appData.txTransferHandle, appData.transmitDataBuffer, 64 );

                            appData.hidDataReceived = false;

                            /* Place a new read request. */
                            USB_DEVICE_HID_ReportReceive (USB_DEVICE_HID_INDEX_0,
                                    &appData.rxTransferHandle, appData.receiveDataBuffer, 64 );
                        }
                        break;

                    default:

                        appData.hidDataReceived = false;

                        /* Place a new read request. */
                        USB_DEVICE_HID_ReportReceive (USB_DEVICE_HID_INDEX_0,
                                &appData.rxTransferHandle, appData.receiveDataBuffer, 64 );
                        break;
                }
예제 #25
0
파일: mmalcam.c 프로젝트: billw2/pikrellcam
  /* In pikrellcam, this callback receives resized I420 frames before
  |  sending them on to a jpeg encoder component which generates the
  |  mjpeg.jpg stream image.  Here we send the frame data to the motion display
  |  routine for possible drawing of region outlines, motion vectors
  |  and/or various status text.  Motion detection was done in the h264
  |  callback and a flag is set there so these two paths can be synchronized
  |  so motion vectors can be drawn on the right frame.
  */
void
I420_video_callback(MMAL_PORT_T *port, MMAL_BUFFER_HEADER_T *buffer)
	{
	CameraObject          *obj = (CameraObject *) port->userdata;
	MMAL_BUFFER_HEADER_T  *buffer_in;
	static struct timeval timer;
	int                   utime;
	static int            encoder_busy_count;

	if (   buffer->length > 0
	    && motion_frame_event
	   )
		{
		motion_frame_event = FALSE;

		/* Do not send buffer to encoder if it has not received the previous
		|  one we sent unless this is the frame we want for a preview save.
		|  In that case, we may be sending a buffer to preview save before
		|  the previous buffer is handled.  This is accounted for below.
		*/
		if (   mjpeg_encoder_send_count == mjpeg_encoder_recv_count
		    || motion_frame.do_preview_save
		   )
			{
			if (obj->callback_port_in && obj->callback_pool_in)
				{
				buffer_in = mmal_queue_get(obj->callback_pool_in->queue);
				if (   buffer_in
				    && obj->callback_port_in->buffer_size >= buffer->length
				   )
					{
					mmal_buffer_header_mem_lock(buffer);
					memcpy(buffer_in->data, buffer->data, buffer->length);
					buffer_in->length = buffer->length;
					mmal_buffer_header_mem_unlock(buffer);
					display_draw(buffer_in->data);

					if (motion_frame.do_preview_save)
						{
						/* If mjpeg encoder has not received previous buffer,
						|  then the buffer to save will be the second buffer
						|  it gets from now. Otherwise it's the next buffer.
						*/
						pthread_mutex_lock(&mjpeg_encoder_count_lock);
						if (mjpeg_encoder_send_count == mjpeg_encoder_recv_count)
							mjpeg_do_preview_save = 1;
						else
							mjpeg_do_preview_save = 2;
						pthread_mutex_unlock(&mjpeg_encoder_count_lock);
						if (mjpeg_do_preview_save == 2 && pikrellcam.debug)
							printf("%s: encoder not clear -> preview save delayed\n",
								fname_base(pikrellcam.video_pathname));
						}
					motion_frame.do_preview_save = FALSE;
					++mjpeg_encoder_send_count;
					mmal_port_send_buffer(obj->callback_port_in, buffer_in);
					}
				}
			}
		else
			{
			++encoder_busy_count;
			if (pikrellcam.debug)
				printf("encoder not clear (%d) -> skipping mjpeg frame.\n",
					   encoder_busy_count);
			if (encoder_busy_count > 2)	/* Frame maybe dropped ??, move on */
				{
				if (pikrellcam.debug)
					printf("  Syncing recv/send counts.\n");
				encoder_busy_count = 0;
				mjpeg_encoder_recv_count = mjpeg_encoder_send_count;
				}
			}
		if (buffer->flags & MMAL_BUFFER_HEADER_FLAG_FRAME_END)
			{
			if (pikrellcam.debug_fps && (utime = micro_elapsed_time(&timer)) > 0)
				printf("%s fps %d\n", obj->name, 1000000 / utime);
			}
		}
	return_buffer_to_port(port, buffer);
	}