專注差異化嵌入式產(chǎn)品解決方案 給智能產(chǎn)品定制注入靈魂給予生命
提供開(kāi)發(fā)工具、應(yīng)用測(cè)試 完善的開(kāi)發(fā)代碼案例庫(kù)分享
從全面的產(chǎn)品導(dǎo)入到強(qiáng)大技術(shù)支援服務(wù) 全程貼心伴隨服務(wù),創(chuàng)造無(wú)限潛能!
提供新的芯片及解決方案,提升客戶產(chǎn)品競(jìng)爭(zhēng)力
提供最新的單片機(jī)資訊,行業(yè)消息以及公司新聞動(dòng)態(tài)
# include # define unch unsigned char # define unint unsigned int # define OE RE0 # define WR RE1 # define GS RE2 //373鎖存器的片選端
//延時(shí)程序 void delay(void) { unint i; for(i = 0;i < 0xfff;i++) continue; } //RAM讀程序 void read(unch *data,unint address,unch num) { unint addressl,addressh; unint i; for(i = 0;i < num;i++,data++) { addressh = address % 256; addressl = address / 256; TRISE = 0x00; //設(shè)置RE端為輸出 TRISD = 0x00; TRISB = 0x00; GS = 1; //鎖存器的使能端 PORTD = addressl; //D口設(shè)置為地址低8位 PORTB = addressh; //A口設(shè)置為地址高5位 asm("nop"); asm("nop"); GS = 0; WR = 1; OE = 0; TRISD = 0xFF; *data = PORTD; //讀入數(shù)據(jù) asm("nop"); asm("nop"); OE = 1; address = address + 1; } } //RAM寫(xiě)程序 void write(unch *data, unint address, unint num) { unint addressl,addressh; unint i; for(i = 0;i < num; i++,data++) { addressh = address % 256; addressl = address / 256; TRISE = 0x00; //設(shè)置RE口為輸出 TRISD = 0x00; TRISB = 0x00; GS = 1; //鎖存器的使能端 PORTD = addressl; //D口設(shè)置為地址低8位 PORTA = addressh; //A口設(shè)置為地址低5位 asm("nop"); asm("nop"); GS = 0; //鎖存地址 WR = 0; PORTD = *data; asm("nop"); asm("nop"); WR = 1; address = address + 1; } }
main() { unch string[],str[5]={0x23,0x34,0x54,0x23,0x72}; write(str,0,5); TRISA = 0xFF; TRISB = 0xFF; TRISE = 0xFF; TRISD = 0xFF; read(string,0,5); while(1); }