Re: 不同的chip
|
||||
---|---|---|---|---|
新會員
|
因為對chip完全沒碰過..
也沒有上過課程... 就突然要用can bus的東西...(ap001...18f458) 所以'想請問有哪些文件可以參考阿...
發表於: 2006/9/26 14:30
|
|||
|
Re: 不同的chip
|
||||
---|---|---|---|---|
中級會員
|
按原理來說pic18f458是18f452的超集,如果在程式裡面沒有使用到18f458的專有功能.程式一般會通用.
但是這樣採用也太魯莽了,最好熟習一下兩個晶片的異同之處方能胸中有竹吧
發表於: 2006/9/25 16:19
|
|||
|
Re: 不同的chip
|
||||
---|---|---|---|---|
版主
|
最好來上一下 workshop 的課,這樣會比較容易上手。
PIC18F458 有多比較器,要觀掉才行。
發表於: 2006/9/22 17:45
|
|||
|
Re: 不同的chip
|
||||
---|---|---|---|---|
新會員
|
拿範例來說
假設F18_config.c是 #pragma romdata CONFIG const rom unsigned char CONFIG1L=0xff ; // Don't care byte const rom unsigned char CONFIG1H=0b00100010 ; // Disable OSC switch , XXXXX010 = HS Osc const rom unsigned char CONFIG2L=0b00000001 ; // Disable PWRT , Disable BOR const rom unsigned char CONFIG2H=0b00000000 ; // Disable WDT timer const rom unsigned char CONFIG3L=0xff ; // Don't care byte const rom unsigned char CONFIG3H=0b00000000 ; // XXXXXXX0 = CCP2 --> RB3 const rom unsigned char CONFIG4L=0b00000001 ; // 0XXXXXXX Backgroung Debug Enable ( ICD ) const rom unsigned char CONFIG4H=0xff ; // Don't care byte const rom unsigned char CONFIG5L=0b00001111 ; // Not PROG code protected const rom unsigned char CONFIG5H=0b11000000 ; // Not EEPROM code protected const rom unsigned char CONFIG6L=0b00001111 ; const rom unsigned char CONFIG6H=0b11100000 ; const rom unsigned char CONFIG7L=0b00001111 ; const rom unsigned char CONFIG7H=0b01000000 ; #pragma romdata Main.c是 //*********************************************** //* Main.C * //*********************************************** //* W-AP002 MPLAB C18 Advance Workshop * //* Written by: Richard Yang * //* Sr. Corporate Applications Engr.* //* Microchip Technology Inc. * //* Date: 16 January 2003 * //* Revision: 1 * //*********************************************** //* 練習一 //* 1. 將 “WAP-002 Workshop” 的字串從 ROM 讀出並顯示在 LCD 螢幕的第一行位置 //* 2. 將你的英文名字顯示在第二行的起始位置 //* 3. 將一數目字從 0 到 9 順序顯示在 LCD 第二行最後一個位置,間格時間 0.5 Sec //* //* 宣告所使用的含入檔 //*********************************************************** #include <p18f452.h> #include <delays.h> #include "P18F_LCD.h" //* 函數原型宣告 //*********************************************************** void InitializePORT(void); //* 定義查表字串及變數並放在 Access Bank 中 //*********************************************************** #pragma idata access My_RAM_1 near char LCD_RAM_MSG[ ]="Richard Yang"; near unsigned char LCD_Char='0'; near unsigned int sum = 0 ; near unsigned int sum1 = 1 , abc = 1, bcd = 0 ; //* 定義LCD顯示的查表字串並放在 ROM 區 //*********************************************************** #pragma romdata RomData const rom char LCD_ROM_MSG[ ] ="WAP-002 Workshop"; #pragma code //*********************************************************** /* */ /* Main Program */ /* */ //*********************************************************** void main(void) { InitializePORT( ); TBLPTR = 0 ; Nop(); if(!sum){ if(sum1){ abc = 0 ; bcd = 1 ; } Nop(); } _asm TBLRDPOSTINC _endasm sum = TABLAT ; // 開啟 LCD 模組 OpenLCD( ); // 在 LCD 第一行顯示字串訊息"WAP-002 Workshop" LCD_Set_Cursor(0,0); putrsLCD(LCD_ROM_MSG); // 在 LCD 第二行顯示你的英文名字 LCD_Set_Cursor(1,0); putsLCD(LCD_RAM_MSG); while(1) { // 設定顯示位置在第二行第15個,顯示一數目字元(0~9)間隔0.5秒 // 延遲函數用 Delay10KTCYx(unsigned char)來完成 // 顯示數字從"0x30" to "0x39" LCD_Set_Cursor(1,15); Delay10KTCYx(200) ; putcLCD(LCD_Char++); if (LCD_Char==0x3A) LCD_Char='0'; } } //************************************************ //* Function: Initialize PORT * //************************************************ void InitializePORT(void) { PORTA=0x00; TRISA=0b11011011; // RA2 as LCD-E control, RA5 as CS Control for SPI PORTD=0x00; TRISD=0x00; // Set PORTD as Output port } #pragma code WAP_LCD.c是 #include <p18f452.h> #include <delays.h> #include "P18F_LCD.h" // // Defines for I/O ports that provide LCD data & control // PORTD[0:3]-->DB[4:7]: Higher order 4 lines data bus with bidirectional // : DB7 can be used as a BUSY flag // PORTA,2 --> [E] : LCD operation start signal control // PORTD,5 --> [RW]: LCD Read/Write control // PORTD,4 --> [RS]: LCD Register Select control // : "0" for Instrunction register (Write), Busy Flag (Read) // : "1" for data register (Read/Write) // #define CPU_SPEED 16 // CPU speed is 16 Mhz !! #define LCD_RS PORTDbits.RD4 // The definition of control pins #define LCD_RW PORTDbits.RD5 #define LCD_E PORTAbits.RA2 #define LCD_DATA LATD // PORTD[0:3] as LCD DB[4:7] //#define LCD_CTRL LATA #define DIR_LCD_DATA TRISD // LCD Module commands #define DISP_2Line_8Bit 0b00111000 #define DISP_2Line_4Bit 0b00101000 #define DISP_ON 0x00C // Display on #define DISP_ON_C 0x00E // Display on, Cursor on #define DISP_ON_B 0x00F // Display on, Cursor on, Blink cursor #define DISP_OFF 0x008 // Display off #define CLR_DISP 0x001 // Clear the Display #define ENTRY_INC 0x006 // #define ENTRY_INC_S 0x007 // #define ENTRY_DEC 0x004 // #define ENTRY_DEC_S 0x005 // #define DD_RAM_ADDR 0x080 // Least Significant 7-bit are for address #define DD_RAM_UL 0x080 // Upper Left coner of the Display #pragma udata unsigned char Temp_CMD ; unsigned char Str_Temp ; unsigned char Out_Mask ; #pragma code void OpenLCD(void) { ADCON1=(ADCON1 & 0xF0)|0b00001110; // Set AN0 for analog input LCD_E=0; LCD_DATA = 0x00; // LCD DB[4:7] & RS & R/W --> Low DIR_LCD_DATA = 0x00; // LCD DB[4:7} & RS & R/W are output function TRISAbits.TRISA2=0; // Set E pin as output LCD_DATA = 0b00000011 ; LCD_CMD_W_Timing() ; LCD_L_Delay() ; LCD_DATA = 0b00000011 ; LCD_CMD_W_Timing() ; LCD_L_Delay() ; LCD_DATA = 0b00000011 ; LCD_CMD_W_Timing() ; LCD_L_Delay() ; LCD_DATA = 0b00000010 ; LCD_CMD_W_Timing() ; LCD_L_Delay() ; WriteCmdLCD(DISP_2Line_4Bit) ; LCD_S_Delay() ; WriteCmdLCD(DISP_ON) ; LCD_S_Delay() ; WriteCmdLCD(ENTRY_INC) ; LCD_S_Delay() ; WriteCmdLCD(CLR_DISP) ; LCD_L_Delay() ; } //********************************************* // _ ______________________________ // RS _>--<______________________________ // _____ // RW \_____________________________ // __________________ // E ____________/ \___ // _____________ ______ // DB _____________>--------------<______ //*********************************************** // Write Command to LCD module // void WriteCmdLCD( unsigned char LCD_CMD) { Temp_CMD = (LCD_CMD & 0xF0)>>4 ; // Send high nibble to LCD bus LCD_DATA= (LCD_DATA & 0xF0)|Temp_CMD ; LCD_CMD_W_Timing () ; Temp_CMD = LCD_CMD & 0x0F ; // Send low nibble to LCD bus LCD_DATA= (LCD_DATA & 0xF0)|Temp_CMD ; LCD_CMD_W_Timing () ; LCD_S_Delay() ; // Delay 100uS for execution } //*********************************************** // Write Data to LCD module // void WriteDataLCD( unsigned char LCD_CMD) { Temp_CMD = (LCD_CMD & 0xF0)>>4 ; // Send high nibble to LCD bus LCD_DATA= (LCD_DATA & 0xF0)|Temp_CMD ; LCD_DAT_W_Timing () ; Temp_CMD = LCD_CMD & 0x0F ; // Send low nibble to LCD bus LCD_DATA= (LCD_DATA & 0xF0)|Temp_CMD ; LCD_DAT_W_Timing () ; LCD_S_Delay() ; // Delay 100uS for execution } void putcLCD(unsigned char LCD_Char) { WriteDataLCD(LCD_Char) ; } void LCD_CMD_W_Timing( void ) { LCD_RS = 0 ; // Set for Command Input Nop(); // LCD_RW = 0 ; Nop(); LCD_E = 1 ; Nop(); Nop(); LCD_E = 0 ; } void LCD_DAT_W_Timing( void ) { LCD_RS = 1 ; // Set for Data Input Nop(); // LCD_RW = 0 ; Nop(); LCD_E = 1 ; Nop(); Nop(); LCD_E = 0 ; } //*********************************************** // Set Cursor position on LCD module // CurY = Line (0 or 1) // CurX = Position ( 0 to 15) // void LCD_Set_Cursor(unsigned char CurY, unsigned char CurX) { WriteCmdLCD( 0x80 + CurY * 0x40 + CurX) ; LCD_S_Delay() ; } //*********************************************** // Put a ROM string to LCD Module // void putrsLCD( const rom char *Str ) { while (1) { Str_Temp = *Str ; if (Str_Temp != 0x00 ) { WriteDataLCD(Str_Temp) ; Str ++ ; } else return ; } } //*********************************************** // Put a RAM string to LCD Module // void putsLCD( char *Str) { while (1) { Str_Temp = *Str ; if (Str_Temp != 0x00 ) { WriteDataLCD(Str_Temp) ; Str ++ ; } else return ; } } void puthexLCD(unsigned char HEX_Val) { unsigned char Temp_HEX ; Temp_HEX = (HEX_Val >> 4) & 0x0f ; if ( Temp_HEX > 9 )Temp_HEX += 0x37 ; else Temp_HEX += 0x30 ; WriteDataLCD(Temp_HEX) ; Temp_HEX = HEX_Val & 0x0f ; if ( Temp_HEX > 9 )Temp_HEX += 0x37 ; else Temp_HEX += 0x30 ; WriteDataLCD(Temp_HEX) ; } // ********************************************************************************* // Delay for atleast 10 ms // ********************************************************************************* void LCD_L_Delay(void) { Delay10KTCYx(CPU_SPEED / 2) ; } // ********************************************************************************* // Delay for 100 us // ********************************************************************************* void LCD_S_Delay(void) { Delay100TCYx(CPU_SPEED) ; } 請問我要如何讓他在 chip是18F458上運作.... 版子是APP001 我將它改成#include <p18f458.h>.. 可是燒上去就是一團黑黑的耶.. 請問要怎嚜解決阿
發表於: 2006/9/22 15:36
|
|||
|
不同的chip
|
||||
---|---|---|---|---|
新會員
|
請問如果她的.c檔是..#include <p18f452.h>...
如果我現在的chip是...18f458... 我只要將include檔改掉.#include <p18f458.h>.就可以了嗎... 對於程式方面還有什麼要修改的地方.... 因為完全是新手.....所以好多地方都不知道...><
發表於: 2006/9/22 12:25
|
|||
|