void LCD_PutChar(unsigned char cx,unsigned char cy,unsigned char chr){ uchar *p,i,s,page; uchar port; chr=0;//消除warning 该变量无用,仅为兼容之前接口 cy--; p=arrow16x16; if(cx<4) { port=1; s=cx<<4; } else { port=2; s=((cx-4)<<4); } for(page=0;page<2;page++) { LCD_WrCmd(port,0xb8+cy*2+page); delayus(100); LCD_WrCmd(port,0x40+s); delayus(100); for(i=0;i<16;i++) { LCD_WrDat(port,*p); delayus(10); p++; } } }
void interrupt VectorNumber_Vatd0compare ATD0Interrupt(void) { uint Vot[7]; PTM=0xaa; ATD0STAT0|=0x7f; delayus(10); Vot0[add]=ATD0DR0; Vot1[add]=ATD0DR1; Vot2[add]=ATD0DR2; Vot3[add]=ATD0DR3; Vot4[add]=ATD0DR4; Vot5[add]=ATD0DR5; Vot6[add]=ATD0DR6; add++; if(add>=50)add=0; Vot[0]=(Vot0[0]+Vot0[1]+Vot0[2]+Vot0[3])/4+(Vot0[4]+Vot[5]+Vot0[6]); Vot[1]=(Vot1[0]+Vot1[1]+Vot1[2]+Vot0[3])/4+(Vot1[4]+Vot[5]+Vot1[6]); Vot[2]=(Vot2[0]+Vot2[1]+Vot2[2]+Vot0[3])/4+(Vot2[4]+Vot[5]+Vot2[6]); Vot[3]=(Vot3[0]+Vot3[1]+Vot3[2]+Vot0[3])/4+(Vot3[4]+Vot[5]+Vot3[6]); Vot[4]=(Vot4[0]+Vot4[1]+Vot4[2]+Vot0[3])/4+(Vot4[4]+Vot[5]+Vot4[6]); Vot[5]=(Vot5[0]+Vot5[1]+Vot5[2]+Vot0[3])/4+(Vot5[4]+Vot[5]+Vot5[6]); Vot[6]=(Vot6[0]+Vot6[1]+Vot6[2]+Vot0[3])/4+(Vot6[4]+Vot[5]+Vot6[6]); ATD0CTL5=0x00; //6:0特殊通道禁止,5:0单次转换 ,4:0单通道轮流采样 delayus(6); }
void DisplayCGRAM(unsigned char cx,unsigned char cy) { uchar *p,i,s,page; uchar port; cy--; p=lbatStateGraph; if(cx<4) { port=1; s=cx<<4; } else { port=2; s=((cx-4)<<4); } for(page=0;page<2;page++) { LCD_WrCmd(port,0xb8+cy*2+page); delayus(100); LCD_WrCmd(port,0x40+s); delayus(100); for(i=0;i<16;i++) { LCD_WrDat(port,*p); delayus(10); p++; } } }
void lcd_disp_sz_char(uchar cy,uchar cx,uchar* chr) { uchar *p,i,s,page; uchar port; getBytesFormGB2312s(chr); p=chrBuf; if(cx<4) { port=1; s=cx<<4; } else { port=2; s=((cx-4)<<4); } for(page=0;page<2;page++) { LCD_WrCmd(port,0xb8+cy*2+page); delayus(100); LCD_WrCmd(port,0x40+s); delayus(100); for(i=0;i<16;i++) { LCD_WrDat(port,*p); delayus(10); p++; } } }
/* * 函数介绍:写入一个字节到595里 * 输入参数:无 * 输出参数:无 * 返回值:无 */ void WriteAByteTo595(uint8 indata) //往 74HC595里写入一个数据。 { uint8 i,data; data = indata; for(i=0;i<8;i++) { CLR_SHCLK; if(data&0x80) { SET_SDATA; } else { CLR_SDATA; } data <<= 1; delayus(2); // delayus(200); SET_SHCLK; delayus(2); // delayus(200); CLR_SHCLK; } }
int spi_byte(uint8_t txbyte) { uint8_t rxbyte = 0; uint8_t bitno; uint8_t bit ; //TODO: Implement CPHA1 for (bitno=0; bitno<8; bitno++) { /* Transmit MSB first */ bit = ((txbyte & 0x80) != 0x00); txbyte <<= 1; gpio_write(config.mosi, bit); delayus(config.tSettle); CLOCK_ACTIVE(); delayus(config.tHold); delayus(config.tFreq); /* Read MSB first */ bit = gpio_read(config.miso); rxbyte = (rxbyte<<1) | bit; CLOCK_IDLE(); delayus(config.tFreq); } return rxbyte; }
void handleButton() { static uint32_t btPrev = 0; uint32_t bt; static uint8_t r, g, b; bt = button(); if (bt) { cam_getFrame((uint8_t *)SRAM0_LOC, SRAM0_SIZE, 0x21, 0, 0, 320, 200); getColor(&r, &g, &b); saturate(&r, &g, &b); led_setRGB(r, g, b); } else if (btPrev) { led_setRGB(0, 0, 0); delayus(50000); led_setRGB(r, g, b); delayus(50000); led_setRGB(0, 0, 0); delayus(50000); led_setRGB(r, g, b); delayus(50000); led_setRGB(0, 0, 0); } btPrev = bt; }
void lcd_disp_sz_SingleBytechar(uchar cy,uchar cx,uchar* chr) { uchar *p,i,s,page; uchar port; getBytesFormASCIIs(chr); p=chrBuf; if(cx<8) { port=1; s=cx<<3; } else { port=2; s=((cx-8)<<3); } for(page=0;page<2;page++) { LCD_WrCmd(port,0xb8+cy*2+page); delayus(100); LCD_WrCmd(port,0x40+s); delayus(100); for(i=0;i<8;i++) { LCD_WrDat(port,*p); delayus(10); p++; } } }
/* * 函数介绍:将595里的数据输出到锁存器里。 * 输入参数:无 * 输出参数:无 * 返回值:无 */ void SetByteOut595(void) { CLR_STCLK; delayus(2); // delayus(200); SET_STCLK; delayus(2); // delayus(200); CLR_STCLK; }
Uint8 fb_fw_read(){ FB_FW_Tris = 1; delayus(1000); if(FB_FW_Read){ delayus(100); if(FB_FW_Read){ return true; } } return false; }
Uint8 fb_tq_read(){ FB_TQ_Tris = 1; delayus(1000); if(FB_TQ_Read){ delayus(100); if(FB_TQ_Read){ return true; } } return false; }
void DRV8834_Go(unsigned char steps) { u8 i = 0; for(i=0;i<steps;i++) { GPIO_ResetBit(6,6); delayus(500); GPIO_SetBit(6,6); //制造上升沿 delayus(500); //STEP频率不大于250KHz } }
void temp_init() { bit s; DQ=1; delayus(8); DQ=0; delayus(80); DQ=1; delayus(14); s=DQ; delayus(20); }
void temp_writeonechar(U8 dat) { U8 i; for(i=0;i<8;i++) { dat>>=1; DQ=0; DQ=CY; delayus(5); DQ=1; } delayus(4); }
void POWER_UP_RESET_CC1100(void) { CSN_H; //上电拉高 delayus(1); // CSN_L; //片选使能 delayus(1); // CSN_H; //选择拉高 delayms(1); //最少延时40us,没有最大时间限制 RESET_CC1100(); //复位命令 }
/************************************************* 名称:DS1302WriteByte *说明:无 *功能:写入8bit数据*调用:delayus() *输入:dat:要写入的数据*输出:无 *************************************************/ void DS1302WriteByte(unsigned char dat) { unsigned char i; SCLK=0; //初始时钟线置为0 delayus(2); for(i=0;i<8;i++) //开始传输8个字节的数据 { SDA=dat&0x01; //取最低位,注意DS1302的数据和地址都是从最低位开始传输的 delayus(2); SCLK=1; //时钟线拉高,制造上升沿,SDA的数据被传输 delayus(2); SCLK=0; //时钟线拉低,为下一个上升沿做准备 dat>>=1; //数据右移一位,准备传输下一位数据 } }
int DynamixelClass::moveSpeed(unsigned char ID, int Position, int Speed) { char Position_H,Position_L,Speed_H,Speed_L; Position_H = Position >> 8; Position_L = Position; // 16 bits - 2 x 8 bits variables Speed_H = Speed >> 8; Speed_L = Speed; // 16 bits - 2 x 8 bits variables Checksum = (~(ID + AX_GOAL_SP_LENGTH + AX_WRITE_DATA + AX_GOAL_POSITION_L + Position_L + Position_H + Speed_L + Speed_H))&0xFF; switchCom(Direction_Pin,Tx_MODE); sendData(AX_START); // Send Instructions over Serial sendData(AX_START); sendData(ID); sendData(AX_GOAL_SP_LENGTH); sendData(AX_WRITE_DATA); sendData(AX_GOAL_POSITION_L); sendData(Position_L); sendData(Position_H); sendData(Speed_L); sendData(Speed_H); sendData(Checksum); delayus(TX_DELAY_TIME); switchCom(Direction_Pin,Rx_MODE); return (read_error()); // Return the read error }
void led_init() { // turn on LEDs (max) led_setPWM(LED_RED, LED_MAX_PWM); led_setPWM(LED_GREEN, LED_MAX_PWM); led_setPWM(LED_BLUE, LED_MAX_PWM); // wait for things to settle... delayus(20000); // get current of each led. This is needed because each LED has a different forward voltage. But current determines // brightness regardless of voltage drop. So we normalize with respect to current for best color accuracy. g_ledOnCurrent[LED_RED] = (float)adc_get(LED_RED_ADCCHAN)/ADC_MAX*ADC_VOLTAGE/LED_RED_RESISTOR; g_ledOnCurrent[LED_GREEN] = (float)adc_get(LED_GREEN_ADCCHAN)/ADC_MAX*ADC_VOLTAGE/LED_GREEN_RESISTOR; g_ledOnCurrent[LED_BLUE] = (float)adc_get(LED_BLUE_ADCCHAN)/ADC_MAX*ADC_VOLTAGE/LED_BLUE_RESISTOR; g_ledVal[LED_RED] = 0xff; g_ledVal[LED_GREEN] = 0xff; g_ledVal[LED_BLUE] = 0xff; // turn off LEDs led_set(0); // set other vals... g_ledScale = LED_DEFAULT_SCALE; led_setMaxCurrent(LED_DEFAULT_MAX_CURRENT); g_chirpUsb->registerModule(g_module); }
void menu_conf_5(){ switch(_uintCur){ case 0: if(_RmRead){ eedata_write(_InverseDisEnable,utrue); }else{ eedata_write(_InverseDisEnable,ufalse); } RESETB_Tris = 0; Nop(); RESETB_Write = 0; delayus(500); RESETB_Write = 1; dis_init(); menu_conf_exit(SAVED15,MENU_5); break; case 1: eedata_write(_Code_Orde,_Menu5Count0); menu_conf_exit(SAVED15,MENU_5); break; case 2: _uintCur = 0; lcd_dis_menu_50(); break; } return; }
static void Snake_Disp() //游戏画面显示 { uint8 p = 16; // for(p=0;p<snake.node;p++)//绘制蛇图像 // { // delayus(500-duty); // DisPoint(snake.x[p],snake.y[p]); // delayus(duty/5); // cdata = 0xff; // } // DisPoint(food.x,food.y);//绘制食物图像 // delayus(duty); // cdata = 0xff; // // for(i=0;i<16;i++) // { // DispRAM[i] = 0; // } while(p--) DispRAM[p]=0; //清除缓存 for(p=0;p<snake.node;p++) //写入新缓存 { DispRAM[snake.y[p]] |= 0x80 >> (snake.x[p]); } // DispRAM[food.y] |= 0x80 >> (food.x); MatxDisp(DispRAM,duty); DisPoint(7-food.x,food.y); delayus(duty); }
void radio_reset(void) { gpio_high(RESET); delayms(150); gpio_low(RESET); delayus(100); }
unsigned int __sramlocalfunc ddr_datatraining(int nMHz) { pDDR_Reg->CSR =0x0; pDDR_Reg->DRR |= RD; delayus(1); pDDR_Reg->CCR |= DTT; dsb(); do{ delayus(1); }while(pGRF_Reg->GRF_MEM_STATUS[2] &0x1); if(pDDR_Reg->CSR & 0x100000) while(1); pDDR_Reg->DRR &= ~RD; return 0; }
void LCD_DispIni(void) { LCD_RST = 0; delayus(1000); LCD_RST = 1; delayus(1000); LCD_WrCmd(1,LCD_DISPON); LCD_WrCmd(1,LCD_STARTROW); delayus(1000); LCD_WrCmd(2,LCD_DISPON); LCD_WrCmd(2,LCD_STARTROW); LCD_DispFill(0x00); LCD_WrCmd(1,LCD_ADDRSTRY+0); LCD_WrCmd(1,LCD_ADDRSTRX+0); LCD_WrCmd(2,LCD_ADDRSTRY+0); LCD_WrCmd(2,LCD_ADDRSTRX+0); }
void WriteCommand(uchar cmd) //写命令 { ce=1; cd=1; rw=0; P0=cmd; delayus(12); ce=0; rw=1; }
//----------------------- // delay50us //----------------------- void delay50us(void) { word i; for (i=0;i<50;i++) { delayus(); } //wdt_reset(); //WDR(); }
void init_oled(){ uint8_t i; OLED_PORT->DDR |= OLED_OMASK; OLED_PORT->CR1 |= OLED_OMASK; init_spi(); delayus(300); OLED_PORT->ODR &= ~(1<<OLED_RST_PIN); delayus(30); OLED_PORT->ODR |= (1<<OLED_RST_PIN); oled_spi_begin(OLED_CMD); for (i = 0; i < sizeof(SSD1306_INIT); i++){ spi_write(SSD1306_INIT[i]); } oled_spi_end(); }
void WriteData(uchar dat) //写数据 { ce=1; cd=0; rw=0; P0=dat; delayus(12); ce=0; rw=1; }
int DynamixelClass::setEndless(unsigned char ID, bool Status) { if ( Status ) { char AX_CCW_AL_LT = 0; // Changing the CCW Angle Limits for Full Rotation. Checksum = (~(ID + AX_GOAL_LENGTH + AX_WRITE_DATA + AX_CCW_ANGLE_LIMIT_L))&0xFF; switchCom(Direction_Pin,Tx_MODE); sendData(AX_START); // Send Instructions over Serial sendData(AX_START); sendData(ID); sendData(AX_GOAL_LENGTH); sendData(AX_WRITE_DATA); sendData(AX_CCW_ANGLE_LIMIT_L ); sendData(AX_CCW_AL_LT); sendData(AX_CCW_AL_LT); sendData(Checksum); delayus(TX_DELAY_TIME); switchCom(Direction_Pin,Rx_MODE); return(read_error()); } else { turn(ID,0,0); Checksum = (~(ID + AX_GOAL_LENGTH + AX_WRITE_DATA + AX_CCW_ANGLE_LIMIT_L + AX_CCW_AL_L + AX_CCW_AL_H))&0xFF; switchCom(Direction_Pin,Tx_MODE); sendData(AX_START); // Send Instructions over Serial sendData(AX_START); sendData(ID); sendData(AX_GOAL_LENGTH); sendData(AX_WRITE_DATA); sendData(AX_CCW_ANGLE_LIMIT_L); sendData(AX_CCW_AL_L); sendData(AX_CCW_AL_H); sendData(Checksum); delayus(TX_DELAY_TIME); switchCom(Direction_Pin,Rx_MODE); return (read_error()); // Return the read error } }
// initiate a soft reset (run code in spifi) when flag is set. void handleReset() { // note, none of this soft reset code works. There is some kind of issue with the spifi coming out of reset. // 1) if you boot into spifi from power-up and run this code (from ram), reset works. // but only if you do soft reset of RGU_SIG_M3. RGU_SIG_CORE won't work, which is consistent with (3) below. // 2) if you boot into dfu from power-up (non-spifi) and run this code, reset fails. // This implies that some state either in the spifi device or the spifi controller isn't being reset/restored correctly // during reset. // 3) if you softreset the spifi, (1) no longer holds. // This implies that the state of the spifi controller is likely causing the reset hang. // 4) reading the state of the spifi controller (registers 0x40003000-0x40003020) shows a change in controller // state regarding (1) and (2), namely 0x40003014, 3018, 301c, but strangely, trying to read 0x40003014 programatically // hangs the processor. // There's this: // http://www.lpcware.com/content/blog/introduction-spifi // which describes how to reset the spifi device. // The Winbond W25Q80BV has a 0xff reset instruction (for stopping a read stream). // But this doesn't help either. // Other sources like the errata: // http://www.nxp.com/documents/errata_sheet/ES_LPC43X0_A.pdf // say that you need to issue a cancel_mem_mode() command beofore resetting. This doesn't work either. // http://www.lpcware.com/content/forum/soft-reset-spifi if (g_resetFlag) { delayus(100000); // wait for USB return packet to be sent #if 0 // reset spifi device SPIFI_CMD =(0xffu << 24) | // opcode 0xFF winbond reset (0x1 << 21) | // frame form indicating opcode only (0x0 << 19) | // field form indicating all serial (0); // datalen while(SPIFI_STAT & 2); // wait for command to complete //RGU_SoftReset(RGU_SIG_SPIFI); // reset spifi controller delayus(100000); // wait for spifi device to reset #endif (*spifi_table.cancel_mem_mode)(&g_spifi); (*spifi_table.cancel_mem_mode)(&g_spifi); delayus(100000); // wait for spifi device to reset RGU_SoftReset(RGU_SIG_CORE); // reset processor while(1); } }
Uint8 l_cl_read(){ L_CL_Tris = 1; Nop(); if(L_CL_Read==0){ delayus(100); if(L_CL_Read==0){ return true; } } return false; }