• slider image 442
  • slider image 483
  • slider image 484
  • slider image 485
  • slider image 486
  • slider image 487
:::


Browsing this Thread:   1 Anonymous Users






Re: 請教Definitions from P16F877.INC
#7
管理員
管理員


查看用戶資訊
您的 C Compiler 好像不是 HI-TECH C 喔 ! 不過在那麼常的程式中很難發現你想要傳達的 . 一般而言在 C 語言中使用 .h file 來做一些定義與宣告的含入. .INC 的檔案比較少見 . 當然檔名也可不依規定來取啦 .

您提到的轉換 ! 是否在 Compiler 與 LINK 階段遇到什麼 Error Message 呢 ?

若你使用的是 CCS 或 HI-TECH C , 可以把問題描述清楚些然後和 Source code 一起傳給我 . 我想這樣比較容易一些 :)

Mail Address : calvin.ho@microchip.com

Best Regards,

發表於: 2005/3/9 23:12
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 請教Definitions from P16F877.INC
#6
新會員
新會員


查看用戶資訊
是C,部分程式如下:

#include <p16f877.h>

#define DEBUG 1
//=============================================================
//
void run_led(void);
void logo(void);
//=============================================================
//Serial communication
void serial_init(void);
void putch(char c);
char getch(void);
void putchhex(char c);
void putst(const char * str);

//=============================================================
//Utilities
char read_bit(char reg,char offset);
void DelayMs(int x);
void DelayUs(int x);
//=============================================================
//SPI
#define TURNON 0xFF
#define TURNOFF 0x00
void spi_init(void);
void dac_out(char data_H, char data_L);
void regulator_init();
void regulator(char status);
//=============================================================
//Ethernet
char txlen,rxlen; //STRANGE!!!!!!
char typecode,opcode,packet_count;
char data_type,send_recv,ack_noack;
char packet[PACKET_SIZE];
char byte_read;
void write_creg(char regaddr, char regdata);
char read_creg(char regaddr);
void init_RTL8019AS();
void send(char size);
char get_packet(void);
void receive(void);
void show_packet(char size);
void exchange_data(void);
void receive_packet(void);
void send_packet(void);
char com_flag,send_flag;
//==============================================================
//Operation
#define MAX_POINT 80
char time[MAX_POINT];
char volt[MAX_POINT];
char interval,num,prescaler;
//char crnt[CUR_POINT];
char data_H,data_L;
int current = 0;
void ad_check(void);
void adc_init(void);
void ad_convert(char type);
void cur_average(void);
int t;
int global_tick = 0;
int local_tick = 0;
void int_init(void);
void interrupt(void);
char data_len;

void main()
{
char temp,t;

serial_init();
logo();
spi_init();
regulator_init();
init_RTL8019AS();
run_led();
adc_init();
int_init();
regulator(TURNON);
#if DEBUG
for(t=0; t < MAX_POINT; t++){
time[t] = t;
volt[t] = t;
}
for (t = 6; t < PACKET_SIZE; t++){
packet[t] = 0x00;
}
#endif
for (t = 0; t < 6; t++){
packet[t] = 0x01;
}
interval = 60;
while(1)//continuous loop
{
exchange_data();
//timer on
int_init();
temp = opcode & EMULATE_VOLTAGE_MASK;
if ( temp == EMULATE_VOLTAGE ){
#if DEBUG
putst("\r\nVoltage Emulate & Current Measure CMD is executing!\r\n");
#endif
enable_interrupt( GIE );
enable_interrupt( T0IE );
temp = opcode & MEASURE_AVG_CURRENT_MASK;
num = data_len / 2;
for (t = 0 ; t < num; t++)
{
data_H = volt[2*t];
data_L = volt[2*t+1];
dac_out(data_H,data_L);
if (temp == MEASURE_AVG_CURRENT){
ad_convert(CURRR);
volt[2*t] = data_H;
volt[2*t+1]= data_L;
}
temp = time[2*t];
while(temp > local_tick)
{
;;
}
local_tick = 0;
#if DEBUG
putst("\r\nTICK = : ");
#endif
}
clear_bit( intcon, GIE );
clear_bit( intcon, T0IE );
cur_average();
#if DEBUG
putst("\r\n\nEmulation has finished!! \r\n");
#endif
}
if ( opcode == 0xC0 ){
#if DEBUG
putst("\r\nVoltage Measure & Current Measure CMD is executing!\r\n");
#endif
enable_interrupt( GIE );
enable_interrupt( T0IE );
for (t = 0 ; t < interval ; t++)
{
num = (global_tick - 1) * 2;
temp = global_tick;
ad_convert(CURRR);
time[num] = data_H;
time[num + 1] = data_L;
ad_convert(VOLTT);
volt[num] = data_H;
volt[num + 1] = data_L;
while (temp == global_tick){
nop();
}
}
#if DEBUG
putst("\r\n\nMeasuring has finished!! \r\n");
#endif
}
//timer off
global_tick = 0;

}
}

發表於: 2005/3/7 15:42
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 請教Definitions from P16F877.INC
#5
新會員
新會員


查看用戶資訊
另外, .h file as below:

// PART = PIC 16F877


#define W 0x0000
#define F 0x0001

//=============================================
// Registers

char indf@0x0000;
char tmr0@0x0001;
char pcl@0x0002;
char status@0x0003;
char fsr@0x0004;
char porta@0x0005;
char portb@0x0006;
char portc@0x0007;
char portd@0x0008;
char porte@0x0009;
char pclath@0x000A;
char intcon@0x000B;
char pir1@0x000C;
char pir2@0x000D;
char tmr1l@0x000E;
char tmr1h@0x000F;
char t1con@0x0010;
char tmr2@0x0011;
char t2con@0x0012;
char sspbuf@0x0013;
char sspcon@0x0014;
char ccpr1l@0x0015;
char ccpr1h@0x0016;
char ccp1con@0x0017;
char rcsta@0x0018;
char txreg@0x0019;
char rcreg@0x001A;
char ccpr2l@0x001B;
char ccpr2h@0x001C;
char ccp2con@0x001D;
char adresh@0x001E;
char adcon0@0x001F;
char option_reg@0x0081;
char trisa@0x0085;
char trisb@0x0086;
char trisc@0x0087;
char trisd@0x0088;
char trise@0x0089;
char pie1@0x008C;
char pie2@0x008D;
char pcon@0x008E;
char sspcon2@0x0091;
char pr2@0x0092;
char sspadd@0x0093;
char sspstat@0x0094;
char txsta@0x0098;
char spbrg@0x0099;
char adresl@0x009E;
char adcon1@0x009F;
char eedata@0x010C;
char eeadr@0x010D;
char eedath@0x010E;
char eeadrh@0x010F;
char eecon1@0x018C;
char eecon2@0x018D;

//=============================================
// STATUS Bits

#define IRP 0x0007
#define RP1 0x0006
#define RP0 0x0005
#define NOT_TO 0x0004
#define NOT_PD 0x0003
#define Z 0x0002
#define DC 0x0001
#define C 0x0000

//=============================================
// INTCON Bits

#define GIE 0x0007
#define PEIE 0x0006
#define T0IE 0x0005
#define INTE 0x0004
#define RBIE 0x0003
#define T0IF 0x0002
#define INTF 0x0001
#define RBIF 0x0000

//=============================================
// PIR1 Bits

#define PSPIF 0x0007
#define ADIF 0x0006
#define RCIF 0x0005
#define TXIF 0x0004
#define SSPIF 0x0003
#define CCP1IF 0x0002
#define TMR2IF 0x0001
#define TMR1IF 0x0000

//=============================================

發表於: 2005/3/7 15:42
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 請教Definitions from P16F877.INC
#4
新會員
新會員


查看用戶資訊
另外, .h file as below:

// PART = PIC 16F877


#define W 0x0000
#define F 0x0001

//=============================================
// Registers

char indf@0x0000;
char tmr0@0x0001;
char pcl@0x0002;
char status@0x0003;
char fsr@0x0004;
char porta@0x0005;
char portb@0x0006;
char portc@0x0007;
char portd@0x0008;
char porte@0x0009;
char pclath@0x000A;
char intcon@0x000B;
char pir1@0x000C;
char pir2@0x000D;
char tmr1l@0x000E;
char tmr1h@0x000F;
char t1con@0x0010;
char tmr2@0x0011;
char t2con@0x0012;
char sspbuf@0x0013;
char sspcon@0x0014;
char ccpr1l@0x0015;
char ccpr1h@0x0016;
char ccp1con@0x0017;
char rcsta@0x0018;
char txreg@0x0019;
char rcreg@0x001A;
char ccpr2l@0x001B;
char ccpr2h@0x001C;
char ccp2con@0x001D;
char adresh@0x001E;
char adcon0@0x001F;
char option_reg@0x0081;
char trisa@0x0085;
char trisb@0x0086;
char trisc@0x0087;
char trisd@0x0088;
char trise@0x0089;
char pie1@0x008C;
char pie2@0x008D;
char pcon@0x008E;
char sspcon2@0x0091;
char pr2@0x0092;
char sspadd@0x0093;
char sspstat@0x0094;
char txsta@0x0098;
char spbrg@0x0099;
char adresl@0x009E;
char adcon1@0x009F;
char eedata@0x010C;
char eeadr@0x010D;
char eedath@0x010E;
char eeadrh@0x010F;
char eecon1@0x018C;
char eecon2@0x018D;

//=============================================
// STATUS Bits

#define IRP 0x0007
#define RP1 0x0006
#define RP0 0x0005
#define NOT_TO 0x0004
#define NOT_PD 0x0003
#define Z 0x0002
#define DC 0x0001
#define C 0x0000

//=============================================
// INTCON Bits

#define GIE 0x0007
#define PEIE 0x0006
#define T0IE 0x0005
#define INTE 0x0004
#define RBIE 0x0003
#define T0IF 0x0002
#define INTF 0x0001
#define RBIF 0x0000

//=============================================
// PIR1 Bits

#define PSPIF 0x0007
#define ADIF 0x0006
#define RCIF 0x0005
#define TXIF 0x0004
#define SSPIF 0x0003
#define CCP1IF 0x0002
#define TMR2IF 0x0001
#define TMR1IF 0x0000

//=============================================

發表於: 2005/3/7 15:38
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 請教Definitions from P16F877.INC
#3
新會員
新會員


查看用戶資訊
是C,部分程式如下:

#include <p16f877.h>

#define DEBUG 1
//=============================================================
//
void run_led(void);
void logo(void);
//=============================================================
//Serial communication
void serial_init(void);
void putch(char c);
char getch(void);
void putchhex(char c);
void putst(const char * str);

//=============================================================
//Utilities
char read_bit(char reg,char offset);
void DelayMs(int x);
void DelayUs(int x);
//=============================================================
//SPI
#define TURNON 0xFF
#define TURNOFF 0x00
void spi_init(void);
void dac_out(char data_H, char data_L);
void regulator_init();
void regulator(char status);
//=============================================================
//Ethernet
char txlen,rxlen; //STRANGE!!!!!!
char typecode,opcode,packet_count;
char data_type,send_recv,ack_noack;
char packet[PACKET_SIZE];
char byte_read;
void write_creg(char regaddr, char regdata);
char read_creg(char regaddr);
void init_RTL8019AS();
void send(char size);
char get_packet(void);
void receive(void);
void show_packet(char size);
void exchange_data(void);
void receive_packet(void);
void send_packet(void);
char com_flag,send_flag;
//==============================================================
//Operation
#define MAX_POINT 80
char time[MAX_POINT];
char volt[MAX_POINT];
char interval,num,prescaler;
//char crnt[CUR_POINT];
char data_H,data_L;
int current = 0;
void ad_check(void);
void adc_init(void);
void ad_convert(char type);
void cur_average(void);
int t;
int global_tick = 0;
int local_tick = 0;
void int_init(void);
void interrupt(void);
char data_len;

void main()
{
char temp,t;

serial_init();
logo();
spi_init();
regulator_init();
init_RTL8019AS();
run_led();
adc_init();
int_init();
regulator(TURNON);
#if DEBUG
for(t=0; t < MAX_POINT; t++){
time[t] = t;
volt[t] = t;
}
for (t = 6; t < PACKET_SIZE; t++){
packet[t] = 0x00;
}
#endif
for (t = 0; t < 6; t++){
packet[t] = 0x01;
}
interval = 60;
while(1)//continuous loop
{
exchange_data();
//timer on
int_init();
temp = opcode & EMULATE_VOLTAGE_MASK;
if ( temp == EMULATE_VOLTAGE ){
#if DEBUG
putst("\r\nVoltage Emulate & Current Measure CMD is executing!\r\n");
#endif
enable_interrupt( GIE );
enable_interrupt( T0IE );
temp = opcode & MEASURE_AVG_CURRENT_MASK;
num = data_len / 2;
for (t = 0 ; t < num; t++)
{
data_H = volt[2*t];
data_L = volt[2*t+1];
dac_out(data_H,data_L);
if (temp == MEASURE_AVG_CURRENT){
ad_convert(CURRR);
volt[2*t] = data_H;
volt[2*t+1]= data_L;
}
temp = time[2*t];
while(temp > local_tick)
{
;;
}
local_tick = 0;
#if DEBUG
putst("\r\nTICK = : ");
#endif
}
clear_bit( intcon, GIE );
clear_bit( intcon, T0IE );
cur_average();
#if DEBUG
putst("\r\n\nEmulation has finished!! \r\n");
#endif
}
if ( opcode == 0xC0 ){
#if DEBUG
putst("\r\nVoltage Measure & Current Measure CMD is executing!\r\n");
#endif
enable_interrupt( GIE );
enable_interrupt( T0IE );
for (t = 0 ; t < interval ; t++)
{
num = (global_tick - 1) * 2;
temp = global_tick;
ad_convert(CURRR);
time[num] = data_H;
time[num + 1] = data_L;
ad_convert(VOLTT);
volt[num] = data_H;
volt[num + 1] = data_L;
while (temp == global_tick){
nop();
}
}
#if DEBUG
putst("\r\n\nMeasuring has finished!! \r\n");
#endif
}
//timer off
global_tick = 0;

}
}

發表於: 2005/3/7 15:35
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 請教Definitions from P16F877.INC
#2
管理員
管理員


查看用戶資訊
您好,

請問是用組合語言或是 C ? 若是 C 的話 , 是哪一家呢 ?
很抱歉我們無法由您的描述中很精確的了解問題. 希望能有進一步的補充說明 , 以便彼此互相交流 !

Thank You Very Much :)

發表於: 2005/3/6 23:12
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


請教Definitions from P16F877.INC
#1
新會員
新會員


查看用戶資訊
請問哪位先進知道有人在定義P16F877.h時,還需要使用inc2h 來做convert.另外,是不是有些c程式需要用c2c plus來compile?

Thanks.

發表於: 2005/3/4 18:01
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部







You can view topic.
不可以 發起新主題
You cannot reply to posts.
You cannot edit your posts.
You cannot delete your posts.
You cannot add new polls.
You cannot vote in polls.
You cannot attach files to posts.
You cannot post without approval.
You cannot use topic type.
You cannot use HTML syntax.
You cannot use signature.
You cannot create PDF files.
You cannot get print page.

[進階搜尋]


:::

Microchip連結

https://www.facebook.com/microchiptechnologytaiwan/
http://www.microchip.com.tw/modules/tad_uploader/index.php?of_cat_sn=13
https://mu.microchip.com/page/tmu
http://elearning.microchip.com.tw/modules/tad_link/index.php?cate_sn=1
https://page.microchip.com/APAC-PrefCenters-TW.html
http://www.microchip.com/
http://www.microchip.com/treelink
http://www.microchipdirect.com/
http://www.microchip.com.cn/newcommunity/index.php?m=Video&a=index&id=103
http://www.microchip.com.tw/modules/tad_uploader/index.php?of_cat_sn=2
http://www.microchip.com.tw/Data_CD/eLearning/index.html
http://www.microchip.com.tw/RTC/RTC_DVD/
https://www.microchip.com/development-tools/
https://www.youtube.com/user/MicrochipTechnology
[ more... ]

教育訓練中心

!開發工具購買
辦法說明 [業界客戶] [教育單位]
----------------------------------
!校園樣品申請
辦法說明 [教師資格] [學生資格]
----------------------------------