我正在使用带有PIC18F45K20的演示板,通过PICKit-3和MPLAB IDEv8.30与C18编译器套件进行编程。我正在尝试生成利用RTC的代码,并且(最终)将每秒闪烁一次LED。我对C非常环保,并且我使用Microchip网站上的示例代码构建了我的代码。我一直试图解决我设法制作的所有错误,但我得到的印象是我完全不正确地完成了这些错误。我可以帮助一些好人帮忙。
对不起代码太乱了。我一直在做很多修改,我已经把注释掉了,没有删除,所以你可以将它与示例代码应该做的比较。我得到的印象是代码不正确地引用标题中的内容,但我不确定如何纠正。
我还将Global Structures行中的项目命名为无符号整数,因为它们之前没有被声明为什么,不确定它们是什么意思,我认为这可能是问题的一部分。我只是在学习C所以我很可能做蠢事。
示例代码来自PIC18 RTCC代码中的Microchip。对于那些拥有它的人来说,关联的头文件位于C18 h文件夹中。
获得的错误:
134:Error [1205] unknown member 'RTCCIE' in '__tag_81'
134:Error [1131] type mismatch in assignment
135:Error [1151] struct or union object designator expected
以上错误传播每一行135 - 146。
感谢您的帮助。
我的代码:
#include <p18f45k20.h>
#include "rtcc.h"
#pragma config FOSC = HS, FCMEN = ON, IESO = ON // CONFIG1H
#pragma config PWRT = OFF, BOREN = OFF, BORV = 30 // CONFIG2L
#pragma config WDTEN = OFF, WDTPS = 32768 // CONFIG2H
#pragma config MCLRE = ON, LPT1OSC = OFF, PBADEN = OFF, CCP2MX = PORTC // CONFIG3H
#pragma config STVREN = ON, LVP = OFF, XINST = OFF // CONFIG4L
#pragma config CP0 = OFF, CP1 = OFF, CP2 = OFF, CP3 = OFF // CONFIG5L
#pragma config CPB = OFF, CPD = OFF // CONFIG5H
#pragma config WRT0 = OFF, WRT1 = OFF, WRT2 = OFF, WRT3 = OFF // CONFIG6L
#pragma config WRTB = OFF, WRTC = OFF, WRTD = OFF // CONFIG6H
#pragma config EBTR0 = OFF, EBTR1 = OFF, EBTR2 = OFF, EBTR3 = OFF // CONFIG7L
#pragma config EBTRB = OFF
//-------------------------------Configuration setting ----------------------------------------------
/**
* Oscillator is configured as HS
* Fail safe monitor is enabled
* watch dog timer is disabled
* Extended instruction mode is disabled
* oscillator switch over is enabled
* CPU clock is not devided
* RTCC clock is derived from T1OSC
*/
//#if defined(__18F46J50) //If the selected device if PIC18F46J50, then apply below settings else user will have to set
//#pragma config OSC=HS, FCMEN=ON, WDTEN=OFF, IESO=ON, XINST=OFF, RTCOSC=INTOSCREF
//#endif
//-------------------------Function Prototypes-----------------------------------------------------------------------------
void Blink_LED(unsigned int number_of_blink);
void RTCC_configure(void);
//-----------------Global structures used in deep sleep library-------------------------------------------------------
unsigned int rtccTimeDate, RtccTimeDate, RtccAlrmTimeDate, RTCCIE, Rtcc_read_TimeDate, mRtcc_Clear_Intr_Status_Bit;
//*******************main function******************************************************
void main(void)
{
unsigned char ANCON0;
TRISB=0x01; //configure the IO [TRIS and LAT register] as desired
LATB = 0x00;
ANCON0 = 0xFF;
mRtcc_Clear_Intr_Status_Bit; //clears the RTCC interrupt status bit
RTCC_configure(); //Configure RTCC using library APIs
//while(PIR3bits.RTCCIF==0) //wait untill alarm is set
//RtccReadTimeDate(&Rtcc_read_TimeDate); //Rtcc_read_TimeDate will have latest time
//Blink_LED(150); //Indicate the alarm
while(1); //End of program
}
void Blink_LED(unsigned int number_of_blink)
{
unsigned int m=0,n=0;
for(n=0;n<number_of_blink;n++)
{
LATB = 0xFE;
for(m=0;m<60000;m++);
LATB = 0x00;
for(m=0;m<60000;m++);
}
}
void RTCC_configure(void)
{
unsigned int i=0,j=0;
RtccInitClock(); //turn on clock source
RtccWrOn(); //write enable the rtcc registers
mRtccSetClockOe(1); //enable RTCC output on RTCC output pin
// mRtccSetInt(1); //Enable RTCC interrupt
PIE3bits.RTCCIE=1; //Set Date and time using global structures defined in libraries
RtccTimeDate.f.hour = 1; //Set Hour
RtccTimeDate.f.min = 0; //Set minute
RtccTimeDate.f.sec = 0; //Set second
RtccTimeDate.f.mday = 04; //Set day
RtccTimeDate.f.mon = 04; //Se month
RtccTimeDate.f.year = 09; //set year
RtccTimeDate.f.wday = 6; //Set which day of the week for the corrsponding date
//Set the alarm time and date using gloabl structures defined in libraries
RtccAlrmTimeDate.f.hour = RtccTimeDate.f.hour; //Set Hour
RtccAlrmTimeDate.f.min = RtccTimeDate.f.min ; //Set minute
RtccAlrmTimeDate.f.sec = RtccTimeDate.f.sec + 4; //alarm after ten seconds
RtccAlrmTimeDate.f.mday = RtccTimeDate.f.mday; //Set day
RtccAlrmTimeDate.f.wday = RtccTimeDate.f.wday; //Set which day of the week for the corrsponding date
RtccAlrmTimeDate.f.mon = RtccTimeDate.f.mon; //Se month
RtccAlrmTimeDate.f.year = RtccTimeDate.f.year; //set year
RtccWriteTimeDate(&RtccTimeDate,1); //write into registers
RtccSetAlarmRpt(RTCC_RPT_TEN_SEC,1); //Set the alarm repeat to every minute
RtccSetAlarmRptCount(5,1); //set alarm repeat count
RtccWriteAlrmTimeDate(&RtccAlrmTimeDate); //write the time for alarm into alarm registers
mRtccOn(); //enable the rtcc
mRtccAlrmEnable(); //enable the rtcc alarm to wake the device up from deep sleep
}