導航:首頁 > 操作系統 > 瑞薩單片機教程

瑞薩單片機教程

發布時間:2022-02-04 07:55:45

㈠ 瑞薩單片機2L系列的快閃記憶體操作是怎麼樣的,有人用過么,發個常式看看,1B我操作過

/************************************************************************************
Name: flash_write
Parameters: Write record data
Returns: Result (Complete or program error or erase error)
Description: Initial setting of SFR registers
************************************************************************************/
unsigned char flash_write(unsigned char *write_addr,unsigned char *data,unsigned size){
unsigned char result = COMPLETE;
unsigned char i;
for(i = 0;i < size ;i++)
{
if(*(write_addr+i) != 0xff)
{
if(block_erase(write_addr + i) != COMPLETE)
{
result = result | PROGRAM_ERR;
return result;
}
//break;
}
}
for(i = 0;i < size ;i++)
{
if( data_write(write_addr, *data ) != COMPLETE ){
/* Program error occurence */
return result = result | PROGRAM_ERR; /* if program error */
//break;
}
/* Next write address update */
write_addr++;
}
return result;

}
unsigned char wflash_write(unsigned char *write_addr,unsigned char *data,unsigned size)
{
unsigned char result = COMPLETE;
unsigned char i;
/*
for(i = 0;i < (size * 2) ;i++)
{
if(*(write_addr+i) != 0xff)
{
if(block_erase(write_addr + i) != COMPLETE)
{
result = result | PROGRAM_ERR;
u1tb = '2';
return result;
}
//break;
}
}
*/
if( data_write(write_addr, 0xaa ) != COMPLETE ){
/* Program error occurence */
//u1tb = '3';
return result = result | PROGRAM_ERR; /* if program error */
//break;
}
write_addr++;
if( data_write(write_addr, 0xaa) != COMPLETE ){
/* Program error occurence */
//u1tb = '4';
return result = result | PROGRAM_ERR; /* if program error */
//break;
}
write_addr++;
for(i = 0;i < (size*2) ;i++)
{
if( data_write(write_addr, *data ) != COMPLETE ){
/* Program error occurence */
//u1tb = '5';
return result = result | PROGRAM_ERR; /* if program error */
//break;
}
/*
write_addr++;
if( data_write(write_addr, (unsigned char)((*data) >> 8)) != COMPLETE ){
// Program error occurence
//u1tb = '6';
return result = result | PROGRAM_ERR; // if program error
//break;
}
// Next write address update
*/
write_addr++;
data++;;
}
return result;
}
/************************************************************************************
Name: block_erase
Parameters: Erase block address
Returns: Erase result
Description: Block erase
************************************************************************************/
unsigned char block_erase(unsigned char *ers_addr){
unsigned char erase_result;
/* If use interrupt then clear i flag... */
/* asm("fclr i "); */

/* flash control register set */
fmr0 = 0x01;
asm(" "); /* Description for preventing the abbreviation by optimization */
fmr0 = 0x03; /* CPU rewrite enable */
fmr1 = 0x80;
asm(" "); /* Description for preventing the abbreviation by optimization */
fmr1 = 0x82; /* EW1 mode */

*ers_addr = 0x20; /* Block erase command write */
*ers_addr = 0xd0; /* Block erase command write */
while( fmr00 != 1 ); /* Ready check */

/* Erase status check */
if( fmr07 == 1 ){
*ers_addr = 0x50; /* Clear stutus register */
erase_result = ERASE_ERR;
}else{
erase_result = COMPLETE;
}
/* flash control register reset */
fmr0 = 0x01; /* CPU rewrite disable */
/* If use interrupt then set i flag... */
/* asm("fset i "); */
return erase_result;
}
/************************************************************************************
Name: data_write
Parameters: Record data address
Returns: Program result
Description: Record program
************************************************************************************/
unsigned char data_write( unsigned char *write_addr,unsigned char write_data){
unsigned char program_result = COMPLETE;
int i; /* loop counter */

/* If use interrupt then clear i flag... */
asm("fclr i ");
/* flash control register set */
fmr0 = 0x01;
asm(" "); /* Description for preventing the abbreviation by optimization */
fmr0 = 0x03; /* CPU rewrite enable */
fmr1 = 0x80;
asm(" "); /* Description for preventing the abbreviation by optimization */
fmr1 = 0x82; /* EW1 mode */

*write_addr = 0x40;
*write_addr = write_data;
while( fmr00 != 1 ); /* Ready check */
/* Program status check */
if( fmr06 == 1 ){
/* Program error */
*write_addr = 0x50; /* Clear stutus register */
program_result = PROGRAM_ERR;
// break;
}
// }

/* flash control register reset */
fmr0 = 0x01; /* CPU rewrite disable */
/* If use interrupt then set i flag... */
asm("fset i ");
return program_result;
}
void data_read(unsigned char *read_addr,unsigned char * read_temp,unsigned char size)
{
for(;size>0;size--)
{
*read_temp = *read_addr;
read_temp++;
read_addr++;
}
}
void wdata_read(unsigned char *read_addr,unsigned short * read_temp,unsigned char size)
{
unsigned i;
for(;size>0;size--)
{
*read_temp = *read_addr;
read_addr++;
*read_temp <<= 8;
*read_temp += *read_addr;
read_temp++;
read_addr++;
}
}
unsigned char WriteFlash(unsigned short *write_dat,unsigned char size)
{
//unsigned char low;
unsigned char *write_addr = 0;
unsigned short low,high,mid;
unsigned char program_result = COMPLETE;
high = NUM_OF_BLOCK;
low = 0;
mid = (high + low)/2;
while(mid < 63 && mid > 0)
{
write_addr = BLOCK_A + mid * SIZE_PRE_BLOCK;
//didn't write
if((*write_addr == 0xaa)&&(*(write_addr + 1) == 0xaa))
{
if((*(write_addr + SIZE_PRE_BLOCK) == 0xff)&&(*(write_addr + SIZE_PRE_BLOCK + 1) == 0xff))
{
write_addr += SIZE_PRE_BLOCK;
//u1tb = '6';
break;
}
else
{
low = mid;
}
}
//is 0xff
else
if((*(write_addr - SIZE_PRE_BLOCK) == 0xaa)&&(*(write_addr - SIZE_PRE_BLOCK + 1) == 0xaa))
{
//u1tb = '7';
break;
}
else
{
high = mid;
}
mid = (high + low)/2;
}
//說明所有的快閃記憶體都寫滿了
u1tb = mid;
if(mid == 63)
{
//將整個快閃記憶體都清零
if(block_erase(BLOCK_A+SIZE_PRE_BLOCK) != COMPLETE)
{
program_result = program_result | ERASE_ERR;
return program_result;
}
if(block_erase(BLOCK_B+SIZE_PRE_BLOCK) != COMPLETE);
{
program_result = program_result | ERASE_ERR;
return program_result;
}
write_addr = BLOCK_A;
}
else if(mid == 0)
{
write_addr = BLOCK_A;
}
/*
else
{
write_addr = BLOCK_A + mid * SIZE_PRE_BLOCK;
}
*/
if(wflash_write(write_addr,(unsigned char *)write_dat,size) != COMPLETE)
{program_result = program_result | PROGRAM_ERR;
//u1tb = '1';
}
return program_result;
}
void ReadFlash(unsigned short * read_temp,unsigned char size)
{
unsigned char *write_addr,temp1,temp2;
unsigned short low,high,mid;
high = NUM_OF_BLOCK;
low = 0;
mid = (high + low)/2;
temp1 = *write_addr;
temp2 = (*write_addr+1);
while(mid < 63 && mid > 0)
{
write_addr = BLOCK_A + mid * SIZE_PRE_BLOCK;
//didn't write
//temp1 = *write_addr;
//temp2 = *(write_addr+1);
if((*write_addr == 0xaa)&&(*(write_addr+1) == 0xaa))
{
//temp1 = *write_addr+SIZE_PRE_BLOCK;
//temp2 = *(write_addr+SIZE_PRE_BLOCK+1);
if((*(write_addr+SIZE_PRE_BLOCK) == 0xff)&&(*(write_addr+SIZE_PRE_BLOCK+1) == 0xff))
{
break;
}
else
{
low = mid;
}
}
//is 0xff
else
{
//temp1 = *write_addr-SIZE_PRE_BLOCK;
//temp2 = *(write_addr-SIZE_PRE_BLOCK+1);
if((*(write_addr - SIZE_PRE_BLOCK) == 0xaa)&&(*(write_addr - SIZE_PRE_BLOCK + 1) == 0xaa))
{
write_addr -= SIZE_PRE_BLOCK;
break;
}
else
{
high = mid;
}
}
//u1tb = mid;
mid = (high + low)/2;
}
u1tb = mid;
if(mid >= 63)
write_addr += SIZE_PRE_BLOCK;
else if(mid == 0)
write_addr = BLOCK_A;
write_addr += 2;
data_read(write_addr,((unsigned char *)read_temp),size);
}
你可以參考一下

㈡ 瑞薩單片機怎樣新建一個工程

如果你用官方提供的軟體 一打開軟體介面就提示你 建 立新工程了
軟體:High-performance Embedded Workshop

㈢ 瑞薩單片機

你說的是瑞薩的哪個族的單片機,不同的族指令也不一樣的,還有個問題就是如果datasheet說明不夠詳細的話,那估計沒有比datasheet更詳細的了,給你個建議,可以去瑞薩的官網查找相關的匯編常式,看看常式中的實現方法,會對你理解指令有幫助的。還有就是想看懂指令,就要把單片機的底層了解透徹。

㈣ 瑞薩單片機的輸入捕捉功能

看R8C的技術手冊,RC作為タイマモード(インプットキャプチャ機能)時。「インプットキャプチャ入力端子選択
TRCIOA、TRCIOB、TRCIOC、TRCIOD端子のいずれか1本または復數本」(datasheet的19.4章P333)這說明是可以同時進行比較使用的,但是你想要四個通道的話就要使用「TRCCR1レジスタのCCLRビットが「0」(フリーランニング動作)」它的計數頻率就是1/fk×65536了。然後就看你的TRCIOR0和TRCIOR1對每個引腳是上沿捕捉還是下沿或者雙邊了。當然其他寄存器也是設置了。當它撲捉到引腳的信號時候TRC寄存器的值會存到相應的TRCGRi(i = A,B,C,D)寄存器,當然你不能使用它的緩沖功能了。比較倉促的回答,希望能給你些許幫助,詳細還是看看它的datasheet吧。

㈤ 2013電賽瑞薩單片機RL78G13的五路AD轉換方法

每1ms讀取一次,每次讀時,讀上一次的初始化的那一路數據,讀完後,初始化下一路。

這個單片機的AD很麻煩,定時器也不好使。還沒有真正的EEPROM。就是價位低點,ROM大點。其它真不怎麼樣。
做個電賽建議換ATMEGA吧。

㈥ 請問有哪位高手學過瑞薩單片機的,我最近接到一個小項目,需要用到瑞薩單片機,能否給我發一點資料。

瑞薩單片機也得分型號啊,我學過M16C,M32C,SH7125等,只是了解一點,你學那一款?公司用的話公司會給你們資料的!

㈦ 學會51單片機之後轉學瑞薩78K0單片機容易嗎

瑞薩78K0我沒有使用過,不過我目前正在使用瑞薩RL78系列,為解決汽車儀表方案的MCU。
根據我使用單片機的經驗,自學51單片機是肯定可以為其他系列的單片機提供幫助的。
不論學習哪種單片機,一上來就聽老師講課,沒有系統地學過大學計算機基礎、C語言、一些數電模電基礎,是肯定會雲里霧里的,何況小日本的單片機我覺得沒那麼容易上手。
我現在使用的這個系列有代碼生成器,不過沒基礎的人即使有這個東西也沒辦法真正的玩轉起來。
現在大學的課程沒以前那樣子以前那樣以傳授知識為主了,多數是任務式的,有些老師自己不懂還要糊弄學生,當然這是極個別的現象。
你盡量多花時間和精力學習51和瑞薩的,單片機都是一通百通的,弄懂了單片機的工作原理,和寄存器配置,學會查看datasheet,多去找一些官方的常式(而不是到網上隨處下載的那種,很多都不負責任地誤人子弟的東西)來琢磨。
祝你成功。

㈧ 瑞薩單片機怎麼操作eeprom

片內的還是片外的?按標准I2C時序操作就行。

㈨ 有用瑞薩單片機的大神嗎求助解決問題,我從keil移植過來的程序,之前我寫在.c和.h文件里,

查看是什麼錯誤咯,然後一個個的改。涉及到寄存器的尤其要注意。
還有就是用戶自定義的關鍵字,比如uchar,一定要把定義的地方也過來。

㈩ 誰有瑞薩rl78/g12單片機的教程或c語言代碼 急急急!

去年第一次聽說這個系列的片子,好像只有官方上有教程

閱讀全文

與瑞薩單片機教程相關的資料

熱點內容
程序員那麼可愛姜逸城初戀 瀏覽:495
modbustcp編程 瀏覽:490
實況為什麼安卓看不了 瀏覽:129
Java多線程Queue 瀏覽:94
雲伺服器499元三年 瀏覽:980
nbd源碼 瀏覽:846
x86在arm上編譯 瀏覽:7
linux怎麼配置網路 瀏覽:307
程序員想要的小禮物 瀏覽:186
java獲取網頁url 瀏覽:624
怎麼做解壓神器泡泡版 瀏覽:966
自己動手做一個c編譯器 瀏覽:929
手機如何鏈接谷歌伺服器地址 瀏覽:137
廢掉一個程序員的武功 瀏覽:249
java樹形演算法 瀏覽:641
通達信加鎖指標源碼怎麼看 瀏覽:754
將同名文件移動到部分同名文件夾 瀏覽:403
擺盪指標加壓力線源碼 瀏覽:915
新一代單片機特徵 瀏覽:770
王者的伺服器什麼時候才修好 瀏覽:281