int main() { unsigned long i; unsigned char ucRet = 0; unsigned long ulValueLength; unsigned long ulData[10]; xPWMotorControl(); HD44780Init(); // // Enable Peripheral SPI0 // xSysCtlPeripheralEnable(SYSCTL_PERIPH_ADC); xSPinTypeADC(ADC0, sA0); // // ADC Channel0 convert once, Software tirgger. // xADCConfigure(xADC0_BASE, xADC_MODE_SCAN_CONTINUOUS, ADC_TRIGGER_PROCESSOR); // // Enable the channel0 // xADCStepConfigure(xADC0_BASE, 0, xADC_CTL_CH0); // // Enable the ADC end of conversion interrupt // //xADCIntEnable(xADC0_BASE, xADC_INT_END_CONVERSION); // // install the call back interrupt // //xADCIntCallbackInit(xADC0_BASE, ADCCallback); // // Enable the NVIC ADC interrupt // //xIntEnable(xINT_ADC0); // // Enable the adc // xADCEnable(xADC0_BASE); // // start ADC convert // xADCProcessorTrigger( xADC0_BASE ); HD44780LocationSet(0, 0); HD44780DisplayString("Hello Nuvoton!"); HD44780LocationSet(0, 1); HD44780DisplayString("Hello CooCox! "); SysCtlDelay(10000000); while(1) { SysCtlDelay(1000000); // // Read the convert value // ulValueLength = xADCDataGet(xADC0_BASE, ulData); if (ulData[0] < 0x30100) { HD44780DisplayClear(); HD44780LocationSet(0, 0); HD44780DisplayString("right"); SendData74HC595(0x60); sD11PinTypePWM(); xPWMStart(xPWMB_BASE, xPWM_CHANNEL7); xGPIOSPinWrite(sD3, 1); } else if(ulData[0] < 0x30300) { HD44780DisplayClear(); HD44780LocationSet(0, 0); HD44780DisplayString("up"); ulDuty++; xPWMDutySet(xPWMB_BASE, xPWM_CHANNEL7, ulDuty); sD11PinTypePWM(); xPWMStart(xPWMB_BASE, xPWM_CHANNEL7); xGPIOSPinWrite(sD3, 1); SysCtlDelay(100000); } else if(ulData[0] < 0x30600) { HD44780DisplayClear(); HD44780LocationSet(0, 0); HD44780DisplayString("dowm"); ulDuty--; xPWMDutySet(xPWMB_BASE, xPWM_CHANNEL7, ulDuty); sD11PinTypePWM(); xPWMStart(xPWMB_BASE, xPWM_CHANNEL7); xGPIOSPinWrite(sD3, 1); SysCtlDelay(100000); } else if(ulData[0] < 0x30900) { HD44780DisplayClear(); HD44780LocationSet(0, 0); HD44780DisplayString("left"); SendData74HC595(0x18); sD11PinTypePWM(); xPWMStart(xPWMB_BASE, xPWM_CHANNEL7); xGPIOSPinWrite(sD3, 1); } else if(ulData[0] < 0x30E00) { HD44780DisplayClear(); HD44780LocationSet(0, 0); HD44780DisplayString("select"); SendData74HC595(0x60); sD11PinTypePWM(); xPWMStart(xPWMB_BASE, xPWM_CHANNEL7); xGPIOSPinWrite(sD3, 1); } else { HD44780DisplayClear(); HD44780LocationSet(0, 0); HD44780DisplayString("Nothing"); xPWMStop(xPWMB_BASE, xPWM_CHANNEL7); xGPIOSPinTypeGPIOOutput(sD11); xGPIOSPinTypeGPIOOutput(sD3); xGPIOSPinWrite(sD11, 0); xGPIOSPinWrite(sD3, 0); } if(ulDuty >= 99) { ulDuty = 99; } if(ulDuty <= 1) { ulDuty = 1; } } // // SD Card Init // ucRet = SDInit(); // // write a block to the card // ucRet = SDBlockWrite(pucBuf, 0); // // Re-init the test buffer to 0 // for(i = 0; i < 512; i++) { pucBuf[i] = 0; } // // Read 1 block from the card // ucRet = SDBlockRead(pucBuf, 0); while(1); }
int initFat() { MBR_structTypedef mbr; BiosParameterBlockFAT16_structTypedef biosParameterBlock; memset((void*)&fat, 0, sizeof(fat_typedef)); memset((void*)&cursor, 0, sizeof(cursor_typedef)); memcpy((char*)fat.currentDirName, (char*)root_str, sizeof(root_str)); if(!cardInfo.ready){ return -1; } SDBlockRead(&mbr, 0); // read mbr int i, j, part_id = -1; for(j = 0;j < 4;j++){ // search fat partition for(i = 0;i < sizeof(partition_system_id) / sizeof(partition_system_id[0]);i++){ if(mbr.partition_table[j].systemID == partition_system_id[i]){ part_id = j; if(partition_system_id[i] == 0xb || partition_system_id[i] == 0xc){ fat.fsType = FS_TYPE_FAT32; } else { fat.fsType = FS_TYPE_FAT16; } } } if(part_id != -1){ break; } } if(part_id == -1){ return FS_ERROR_TYPE; } fat.biosParameterBlock = mbr.partition_table[part_id].relative_sectors; // bios parameter block start sector SDBlockRead(&biosParameterBlock, fat.biosParameterBlock); // read bios parameter block if(biosParameterBlock.bytesPerSector != 512){ // bytes/cluster must be 512B debug.printf("\r\nbiosParameterBlock.bytesPerSector:%d", biosParameterBlock.bytesPerSector); return FS_ERROR_BYTES_PER_CLUSTER; } if((fat.sectorsPerCluster = biosParameterBlock.sectorsPerCluster) < 1){ // cluster size return FS_ERROR_CLUSTER_SIZE; } fat.bytesPerCluster = fat.sectorsPerCluster * 512; // bytes/cluster fat.clusterDenomShift = 0; while(!(fat.bytesPerCluster & (1 << fat.clusterDenomShift++))){}; // Cluster bytes right shift denominator fat.clusterDenomShift = fat.clusterDenomShift - 1; fat.reservedSectors = biosParameterBlock.reservedSectors; if(fat.fsType == FS_TYPE_FAT16){ fat_func.getNCluster = getNClusterCache; fat.sectorsPerFAT = biosParameterBlock.sectorsPerFAT; // sectors/FAT fat.rootDirEntry = fat.biosParameterBlock + fat.reservedSectors + fat.sectorsPerFAT * 2; // root directory entry fat.userDataSector = fat.rootDirEntry + 0x20; // user data sector } else { fat_func.getNCluster = getNClusterCache; BiosParameterBlockFAT32_structTypedef *biosParameterBlockFAT32; biosParameterBlockFAT32 = (BiosParameterBlockFAT32_structTypedef*)&biosParameterBlock; fat.sectorsPerFAT = biosParameterBlockFAT32->bigSectorsPerFAT; // sectors/FAT fat.userDataSector = fat.biosParameterBlock + fat.reservedSectors + fat.sectorsPerFAT * 2; // user data sector fat.rootDirEntry = (uint32_t)(biosParameterBlockFAT32->rootDirStrtClus - 2) * fat.sectorsPerCluster + fat.userDataSector; // root directory entry } fat.fatTable = fat.biosParameterBlock + fat.reservedSectors; fat.currentDirEntry = fat.rootDirEntry; makeFileList(); return 0; }