# Camera OV7670 第06段 UDR CLKPR ```javascript= // this is called in Arduino setup() function // 這在呼叫 Arduino setup() 函數 void initializeScreenAndCamera() { // 初始化螢幕和相機 // Enable this for WAVGAT CPUs // (為 WVGAT CPU 啟用此功能) // For UART communiation we want to set WAVGAT Nano to 16Mhz to match Atmel based Arduino // (對於 UART 通信,我們希望將 WVGAT Nano 設置為 16Mhz 以匹配基於 Atmel 的 Arduino) // CLKPR = 0x80; //enter clock rate change mode // 0b1000 0000 (進入時鐘頻率改變模式) // CLKPR = 1; // set prescaler to 1. WAVGAT MCU has it 3 by default. // (將預分頻器設置為 1。WAVGAT MCU 默認為 3。) Serial.begin(baud); if (camera.init()) { sendBlankFrame(COLOR_GREEN); delay(1000); } else { sendBlankFrame(COLOR_RED); delay(3000); } } void sendBlankFrame(uint16_t color) { uint8_t colorH = (color >> 8) & 0xFF; uint8_t colorL = color & 0xFF; commandStartNewFrame(UART_PIXEL_FORMAT_RGB565); for (uint16_t j=0; j<lineCount; j++) { for (uint16_t i=0; i<lineLength; i++) { waitForPreviousUartByteToBeSent(); UDR0 = formatRgbPixelByteH(colorH); waitForPreviousUartByteToBeSent(); UDR0 = formatRgbPixelByteL(colorL); } } } ``` ## UDR0 UDR :USART I/O Data Register 資料暫存器, 分為 TxB (Transmitter Buffer) 與 RxB (Receiver Buffer) 。 讀取 UDR 就是讀取 RxB 內容,寫入 UDR 就是將資料放進 TxB 中等待傳輸。 參考資料(https://medium.com/%E9%96%B1%E7%9B%8A%E5%A6%82%E7%BE%8E/arduino-avr-16-usart-synchronous-mode-9a44c9c2d426) 參考資料(http://epaper.gotop.com.tw/epaper/Q1609/%E3%80%90%E6%9B%B8%E6%91%9868%E3%80%91A454.pdf) :::spoiler 補充CLKPR | value | division | | ----- | -------- | | 0 | 1 (16MHz) | | 1 | 2 (8MHz) | | 2 | 4 (4MHz) | | 3 | 8(2MHz) | | 4 | 16(1MHz) | | 5 | 32(500kHz) | | 6 | 64(250kHz) | | 7 | 128(125kHz) | | 8 | 256(62.5kHz) | 參考網站(https://www.avrfreaks.net/sites/default/files/forum_attachments/LGT8F88P%20LGT8F168P%20LGT8F328P%20translated.pdf) :::
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up