//lcd初始化程序 void lcdinit() { DelayNus(3000); P2DIR |= BIT0|BIT1|BIT2|BIT3|BIT4|BIT5; writecom(0x02); // 数据指针清零 //DelayNus(1000); //writecom(0x28); //DelayNus(1000); //writecom(0x28); //DelayNus(1000); writecom(0x28); //DelayNus(1000); writecom(0x0c); //DelayNus(1000); writecom(0x01); //DelayNus(1000); writecom(0x06); //DelayNus(1000); //writecom(0x80); }
//ÏÔʾ×Ö·û void LCD_write_int(unsigned char x,unsigned char y,unsigned char data) { unsigned char address; //дµØÖ· if (y == 0) { address = 0x80 + x; } else { address = 0xc0 + x; } writecom( address); _delay_cycles(1); writedata(data); }
//lcd初始化程序 void lcdinit() { _delay_cycles(500); writecom(0x33); _delay_cycles(100); writecom(0x32); _delay_cycles(100); writecom(0x28); _delay_cycles(100); writecom(0x0c); _delay_cycles(100); writecom(0x01); _delay_cycles(100); writecom(0x06); _delay_cycles(100); writecom(0x80); }
void initlcd(void) { _RES = 1; // Set _RES HIGH. _SCE = 1; // Disable Chip. _RES = 0; // Reset the LCD. DelayMs(100); // Wait 100ms. _RES = 1; // Awake LCD from RESET state. writecom(0x21); // Activate Chip and H=1. writecom(0xC2); // Set LCD Voltage to about 7V. writecom(0x13); // Adjust voltage bias. writecom(0x20); // Horizontal addressing and H=0. writecom(0x09); // Activate all segments. clearram(); // Erase all pixel on the DDRAM. writecom(0x08); // Blank the Display. writecom(0x0C); // Display Normal. cursorxy(0,0); // Cursor Home. }
//LCDÔÚÈÎÒâλÖÃд×Ö·û´® //ÁÐx=0~15,ÐÐy=0,1 void LCD_write_string(unsigned char x,unsigned char y,unsigned char *s) { unsigned char address; //дµØÖ· if (y == 0) { address = 0x80 + x; } else { address = 0xc0 + x; } writecom(address); _delay_cycles(1); while (*s) // дÏÔʾ×Ö·û´® { writedata(*s); _delay_cycles(1); s++; } }
//LCD在任意位置写字符串 //列x=0~15,行y=0,1 void LCD_write_string(unsigned char x,unsigned char y,char *s) { unsigned char address; //写地址 if (y == 0) { address = 0x80 + x; } else { address = 0xc0 + x; } writecom( address); __delay_cycles(1); while (*s) // 显示字符 { writedata( *s ); __delay_cycles(1); s++; } }
//*************************************************************************** void initLCD() { short_dly(SHORT); writecom(0x30,0); //wake up short_dly(SHORT); writecom(0x30,0); //wake up short_dly(SHORT); writecom(0x30,0); //wake up short_dly(SHORT); writecom(0x39,0); //function set short_dly(SHORT); writecom(0x14,0); //internal osc frequency short_dly(SHORT); writecom(0x56,0); //power control short_dly(SHORT); writecom(0x6D,0); //follower control short_dly(SHORT); writecom(0x79,0); //contrast was 70,0 short_dly(SHORT); writecom(0x0C,0); //display on short_dly(SHORT); writecom(0x06,0); //entry mode short_dly(SHORT); writecom(0x01,0); //clear short_dly(SHORT); }
//********************************************************************************************** //********************************************************************************************** //********************************************************************************************** int main(void) { volatile unsigned char data, pos; WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer //if (CALBC1_12MHZ==0xFF || CALDCO_12MHZ == 0xFF) // while(1); // If calibration constants erased do not load - trap CPU BCSCTL1 = CALBC1_12MHZ; // Set DCO DCOCTL = CALDCO_12MHZ; //********************************************** //DO NOT CHANGE THE ORDER OF THE FOLLOWING CODE! port_init(); initLCD(); P4OUT |= BIT1; //LCD backlight on writecom(0x01, 0);//mode=0 instruction/command, mode=1 data clear display writecom(0x02, 0);//mode=0 instruction/command, mode=1 data position cursor home home write_string_to_LCD("DLP Design ", 16); writecom(0xC0, 0);//mode=0 instruction/command, mode=1 data position cursor to start of second row write_string_to_LCD("DLP-RFID2 Demo ", 16); keep_local=0;//if high, keep data returned to demo board (from reader) local instead of forwarding to host PC via USB. if low, send to host PC. rx_index=0;//init the receive buffer index run_mode=0;//disable inventories blkaddr=0; currentantswstate = ANTSWINT;//init to internal /* Code showing how to use J2, "SEL" User Defined Jumper //pullup resistor enabled for P6.7 in port_init(); data = P6IN; //read port 6 data = data & 0x80; //mask off other port bits if(data>0) //if P6.7 is high (default) */ uart_init(); setup_interrupts(); //ping reader twice to sync and stop transmitting 'D's short_dly(50000);//pause for remainder of packet ping_reader();//ping for presence of reader and update display short_dly(50000);//pause for remainder of packet ping_reader();//ping for presence of reader and update display short_dly(50000);//pause for remainder of packet //********************************************** set_output_mode(); for (;;) { if(light_pressed()) P4OUT ^= 0x02; //toggle P4.1 if(ping_pressed()) ping_reader();//ping for presence of reader and update display if(antsw_pressed()) toggle_antenna_switch();//toggle between internal and external antenna if(run_pressed()) enter_run_mode();//setup for reading UIDs and set run flag for continuous inventories if(stop_pressed()) exit_run_mode();//setup for reading UIDs and set run flag for continuous inventories if(rfoff_pressed()) turn_rf_off(); if(rdblk_pressed()) read_block(); if(run_mode==1) single_slot_inventory(); } }
//************************************************************************************************** void single_slot_inventory()//setup for reading UIDs and set run flag for continuous inventories { unsigned char pos, index; unsigned char uid_buf[20]; //writecom(0x02, 0);//mode=0 instruction/command, mode=1 data home //write_string_to_LCD("run mode... ", 16); rx_index=0;//prepare receive index keep_local=1;//if high, keep data returned to demo board (from reader) local instead of forwarding to host PC via USB. if low, send to host PC. //send write request //set up for reading UIDs pos=0; big_buffer_tx[pos++] = 0x30;//0 big_buffer_tx[pos++] = 0x31;//1 big_buffer_tx[pos++] = 0x30;//0 big_buffer_tx[pos++] = 0x43;//C big_buffer_tx[pos++] = 0x30;//0 big_buffer_tx[pos++] = 0x30;//0 big_buffer_tx[pos++] = 0x30;//0 big_buffer_tx[pos++] = 0x33;//3 big_buffer_tx[pos++] = 0x30;//0 big_buffer_tx[pos++] = 0x34;//4 big_buffer_tx[pos++] = 0x31;//1 big_buffer_tx[pos++] = 0x30;//0 big_buffer_tx[pos++] = 0x30;//0 big_buffer_tx[pos++] = 0x30;//0 big_buffer_tx[pos++] = 0x32;//2 big_buffer_tx[pos++] = 0x31;//1 big_buffer_tx[pos++] = 0x30;//0 big_buffer_tx[pos++] = 0x31;//1 big_buffer_tx[pos++] = 0x30;//0 big_buffer_tx[pos++] = 0x32;//2 read UIDs big_buffer_tx[pos++] = 0x30;//0 big_buffer_tx[pos++] = 0x30;//0 big_buffer_tx[pos++] = 0x30;//0 big_buffer_tx[pos++] = 0x30;//0 send_buffer(pos); while(rx_index< 10); short_dly(20000); rx_index=0;//ignore return data for(pos=0; pos<200; pos++) big_buffer_rx[pos]=0; //send AGC Toggle pos=0; big_buffer_tx[pos++] = 0x30;//0 big_buffer_tx[pos++] = 0x31;//1 big_buffer_tx[pos++] = 0x30;//0 big_buffer_tx[pos++] = 0x39;//9 big_buffer_tx[pos++] = 0x30;//0 big_buffer_tx[pos++] = 0x30;//0 big_buffer_tx[pos++] = 0x30;//0 big_buffer_tx[pos++] = 0x33;//3 big_buffer_tx[pos++] = 0x30;//0 big_buffer_tx[pos++] = 0x34;//4 big_buffer_tx[pos++] = 0x46;//F big_buffer_tx[pos++] = 0x30;//0 big_buffer_tx[pos++] = 0x30;//0 big_buffer_tx[pos++] = 0x30;//0 big_buffer_tx[pos++] = 0x30;//0 big_buffer_tx[pos++] = 0x30;//0 big_buffer_tx[pos++] = 0x30;//0 big_buffer_tx[pos++] = 0x30;//0 send_buffer(pos); while(rx_index< 12); short_dly(20000); rx_index=0;//ignore return data for(pos=0; pos<200; pos++) big_buffer_rx[pos]=0; //send AM/PM toggle pos=0; big_buffer_tx[pos++] = 0x30;//0 big_buffer_tx[pos++] = 0x31;//1 big_buffer_tx[pos++] = 0x30;//0 big_buffer_tx[pos++] = 0x39;//9 big_buffer_tx[pos++] = 0x30;//0 big_buffer_tx[pos++] = 0x30;//0 big_buffer_tx[pos++] = 0x30;//0 big_buffer_tx[pos++] = 0x33;//3 big_buffer_tx[pos++] = 0x30;//0 big_buffer_tx[pos++] = 0x34;//4 big_buffer_tx[pos++] = 0x46;//F big_buffer_tx[pos++] = 0x31;//1 big_buffer_tx[pos++] = 0x46;//F big_buffer_tx[pos++] = 0x46;//F big_buffer_tx[pos++] = 0x30;//0 big_buffer_tx[pos++] = 0x30;//0 big_buffer_tx[pos++] = 0x30;//0 big_buffer_tx[pos++] = 0x30;//0 send_buffer(pos); while(rx_index< 12); short_dly(9000); rx_index=0;//ignore return data while(rx_index>0) { rx_index=0;//ignore return data short_dly(9000); } for(pos=0; pos<200; pos++) big_buffer_rx[pos]=0; //send single slot inventory request pos=0; big_buffer_tx[pos++] = 0x30;//0 big_buffer_tx[pos++] = 0x31;//1 big_buffer_tx[pos++] = 0x30;//0 big_buffer_tx[pos++] = 0x38;//8 big_buffer_tx[pos++] = 0x30;//0 big_buffer_tx[pos++] = 0x30;//0 big_buffer_tx[pos++] = 0x30;//0 big_buffer_tx[pos++] = 0x33;//3 big_buffer_tx[pos++] = 0x30;//0 big_buffer_tx[pos++] = 0x34;//4 big_buffer_tx[pos++] = 0x31;//1 big_buffer_tx[pos++] = 0x34;//4 big_buffer_tx[pos++] = 0x32;//2 big_buffer_tx[pos++] = 0x36;//6 big_buffer_tx[pos++] = 0x30;//0 big_buffer_tx[pos++] = 0x31;//1 big_buffer_tx[pos++] = 0x30;//0 big_buffer_tx[pos++] = 0x30;//0 big_buffer_tx[pos++] = 0x30;//0 big_buffer_tx[pos++] = 0x30;//0 big_buffer_tx[pos++] = 0x30;//0 big_buffer_tx[pos++] = 0x30;//0 send_buffer(pos); while(rx_index < 52);//wait for inventory results short_dly(9000);//pause for remainder of packet writecom(0x02, 0);//mode=0 instruction/command, mode=1 data home if(rx_index < 62) //if empty packet [] or multiple tags in fiend { write_string_to_LCD("NO TAG FOUND ", 16); } else { index=65; for(pos=0; pos<16; pos+=2) { uid_buf[pos] = big_buffer_rx[index]; uid_buf[pos+1] = big_buffer_rx[index+1]; index-=2; } //send received data to LCD display for(pos=0; pos<16; pos++) writecom(uid_buf[pos], 1);//mode=0 instruction/command, mode=1 data C } keep_local=0;//if high, keep data returned to demo board (from reader) local instead of forwarding to host PC via USB. if low, send to host PC. rx_index=0;//prepare receive index update_lcd_line2();//show line 2 }
//************************************************************************************************** void read_block() { unsigned char pos, index; unsigned char uid_buf[20]; rx_index=0;//prepare receive index keep_local=1;//if high, keep data returned to demo board (from reader) local instead of forwarding to host PC via USB. if low, send to host PC. //send write request //set up for reading UIDs pos=0; big_buffer_tx[pos++] = 0x30;//0 big_buffer_tx[pos++] = 0x31;//1 big_buffer_tx[pos++] = 0x30;//0 big_buffer_tx[pos++] = 0x43;//C big_buffer_tx[pos++] = 0x30;//0 big_buffer_tx[pos++] = 0x30;//0 big_buffer_tx[pos++] = 0x30;//0 big_buffer_tx[pos++] = 0x33;//3 big_buffer_tx[pos++] = 0x30;//0 big_buffer_tx[pos++] = 0x34;//4 big_buffer_tx[pos++] = 0x31;//1 big_buffer_tx[pos++] = 0x30;//0 big_buffer_tx[pos++] = 0x30;//0 big_buffer_tx[pos++] = 0x30;//0 big_buffer_tx[pos++] = 0x32;//2 big_buffer_tx[pos++] = 0x31;//1 big_buffer_tx[pos++] = 0x30;//0 big_buffer_tx[pos++] = 0x31;//1 big_buffer_tx[pos++] = 0x30;//0 big_buffer_tx[pos++] = 0x30;//0 read user memory blocks big_buffer_tx[pos++] = 0x30;//0 big_buffer_tx[pos++] = 0x30;//0 big_buffer_tx[pos++] = 0x30;//0 big_buffer_tx[pos++] = 0x30;//0 send_buffer(pos); while(rx_index< 10); short_dly(20000); rx_index=0;//ignore return data for(pos=0; pos<200; pos++) big_buffer_rx[pos]=0; //send AGC Toggle pos=0; big_buffer_tx[pos++] = 0x30;//0 big_buffer_tx[pos++] = 0x31;//1 big_buffer_tx[pos++] = 0x30;//0 big_buffer_tx[pos++] = 0x39;//9 big_buffer_tx[pos++] = 0x30;//0 big_buffer_tx[pos++] = 0x30;//0 big_buffer_tx[pos++] = 0x30;//0 big_buffer_tx[pos++] = 0x33;//3 big_buffer_tx[pos++] = 0x30;//0 big_buffer_tx[pos++] = 0x34;//4 big_buffer_tx[pos++] = 0x46;//F big_buffer_tx[pos++] = 0x30;//0 big_buffer_tx[pos++] = 0x30;//0 big_buffer_tx[pos++] = 0x30;//0 big_buffer_tx[pos++] = 0x30;//0 big_buffer_tx[pos++] = 0x30;//0 big_buffer_tx[pos++] = 0x30;//0 big_buffer_tx[pos++] = 0x30;//0 send_buffer(pos); while(rx_index< 12); short_dly(20000); rx_index=0;//ignore return data for(pos=0; pos<200; pos++) big_buffer_rx[pos]=0; //send AM/PM toggle pos=0; big_buffer_tx[pos++] = 0x30;//0 big_buffer_tx[pos++] = 0x31;//1 big_buffer_tx[pos++] = 0x30;//0 big_buffer_tx[pos++] = 0x39;//9 big_buffer_tx[pos++] = 0x30;//0 big_buffer_tx[pos++] = 0x30;//0 big_buffer_tx[pos++] = 0x30;//0 big_buffer_tx[pos++] = 0x33;//3 big_buffer_tx[pos++] = 0x30;//0 big_buffer_tx[pos++] = 0x34;//4 big_buffer_tx[pos++] = 0x46;//F big_buffer_tx[pos++] = 0x31;//1 big_buffer_tx[pos++] = 0x46;//F big_buffer_tx[pos++] = 0x46;//F big_buffer_tx[pos++] = 0x30;//0 big_buffer_tx[pos++] = 0x30;//0 big_buffer_tx[pos++] = 0x30;//0 big_buffer_tx[pos++] = 0x30;//0 send_buffer(pos); while(rx_index< 12); short_dly(9000); rx_index=0;//ignore return data while(rx_index>0) { rx_index=0;//ignore return data short_dly(9000); } for(pos=0; pos<200; pos++) big_buffer_rx[pos]=0; //build and send the Read block command pos=0; big_buffer_tx[pos++] = 0x30;//0 big_buffer_tx[pos++] = 0x31;//1 big_buffer_tx[pos++] = 0x30;//0 big_buffer_tx[pos++] = 0x42;//B big_buffer_tx[pos++] = 0x30;//0 big_buffer_tx[pos++] = 0x30;//0 big_buffer_tx[pos++] = 0x30;//0 big_buffer_tx[pos++] = 0x33;//3 big_buffer_tx[pos++] = 0x30;//0 big_buffer_tx[pos++] = 0x34;//4 big_buffer_tx[pos++] = 0x31;//1 big_buffer_tx[pos++] = 0x38;//8 big_buffer_tx[pos++] = 0x30;//0 big_buffer_tx[pos++] = 0x30;//0 big_buffer_tx[pos++] = 0x32;//2 big_buffer_tx[pos++] = 0x30;//0 big_buffer_tx[pos++] = 0x30;//addr msb big_buffer_tx[pos++] = 0x30+blkaddr;//addr lsb big_buffer_tx[pos++] = 0x30;//0 big_buffer_tx[pos++] = 0x30;//0 big_buffer_tx[pos++] = 0x30;//0 big_buffer_tx[pos++] = 0x30;//0 send_buffer(pos); while(rx_index< 12); short_dly(30000); writecom(0x02, 0);//mode=0 instruction/command, mode=1 data home if(rx_index < 41) //if empty packet [] or multiple tags in fiend { write_string_to_LCD("NO TAG FOUND ", 16); } else { index=48; for(pos=0; pos<8; pos+=2) { uid_buf[pos] = big_buffer_rx[index]; uid_buf[pos+1] = big_buffer_rx[index+1]; index-=2; } writecom(0x02, 0);//mode=0 instruction/command, mode=1 data home write_string_to_LCD(" ", 16); writecom(0x02, 0);//mode=0 instruction/command, mode=1 data home write_string_to_LCD("BLK ", 4); write_int_to_LCD(blkaddr); write_string_to_LCD(": ", 2); //send received data to LCD display for(pos=0; pos<8; pos++) writecom(uid_buf[pos], 1);//mode=0 instruction/command, mode=1 data C } blkaddr++; if(blkaddr>7) blkaddr=0; keep_local=0;//if high, keep data returned to demo board (from reader) local instead of forwarding to host PC via USB. if low, send to host PC. rx_index=0;//prepare receive index update_lcd_line2();//show line 2 }
/* * Scan the JPEG file for Exif data and parse it. */ static int doit(FILE *fp, const char *fname) { int mark, gotapp1, first, rc; unsigned int len, rlen; unsigned char *exifbuf; struct exiftags *t; long app1; gotapp1 = FALSE; first = 0; exifbuf = NULL; rc = 0; while (jpegscan(fp, &mark, &len, !(first++))) { if (mark != JPEG_M_APP1) { if (fseek(fp, len, SEEK_CUR)) exifdie((const char *)strerror(errno)); continue; } exifbuf = (unsigned char *)malloc(len); if (!exifbuf) exifdie((const char *)strerror(errno)); app1 = ftell(fp); rlen = fread(exifbuf, 1, len, fp); if (rlen != len) { fprintf(stderr, "%s: error reading JPEG (length " "mismatch)\n", fname); free(exifbuf); return (1); } gotapp1 = TRUE; t = exifscan(exifbuf, len, FALSE); if (t && t->props) { if (bflag || com) rc = writecom(fp, fname, app1, findprop(t->props, tags, EXIF_T_USERCOMMENT), exifbuf, t->md.btiff); else rc = printcom(fname, findprop(t->props, tags, EXIF_T_USERCOMMENT), t->md.btiff); } else { fprintf(stderr, "%s: couldn't find Exif properties\n", fname); rc = 1; } exiffree(t); free(exifbuf); } if (!gotapp1) { fprintf(stderr, "%s: couldn't find Exif data\n", fname); return (1); } return (rc); }
void cursorxy(char x, char y) { writecom(0x40|(y&0x07)); // Y axis writecom(0x80|(x&0x7f)); // X axis }