void idle_init(void)
{
- INTCON = _TMR0IE & ~(_TMR0IF | _INT0IF | _RBIF); // Enable tmr0 as interrupt and clear interrupt flags.
+ INTCON = INTCON & ~(_TMR0IF | _INT0IF | _RBIF); // Enable tmr0 as interrupt and clear interrupt flags.
INTCON2 = ~_TMR0IP & _TMR0IP; // Interrupt is lower.
- WDTCON = 0; // OK? WDT=Disabled.
+
+ WDTCON = 1; // OK? WDT=Disabled.
}
/* Enable IDLE */
osccon = OSCCON;
- osccon = osccon | _IDLEN | _SCS1 | _SCS0;
+// osccon = osccon | _IDLEN | _SCS1 | _SCS0;
+ osccon = osccon | _IDLEN & 0b11111100;
OSCCON = osccon;
+ INTCON |= _TMR0IE; // Enable tmr0 as interrupt and clear interrupt flags.
/* Set TMR0 for interrupt*/
- /* Pre-scaler: 1/16, PSA=0(ON), TOSE=0, T0CS=0(INTERNAL), T08BIT=1(8bit), TMR0ON=1(START) */
- contword = _T0PS0 | _T0PS1 | _T08BIT | _TMR0ON; // _T0PS2
- TMR0L = initial & 0xff;
+ /* Pre-scaler: 1/16, PSA=0(ON), TOSE=0, T0CS=0(INTERNAL), T08BIT=0(16bit), TMR0ON=1(START) */
+ contword = _T0PS0 | _T0PS1 | _TMR0ON; // _T0PS2
+// TMR0H = initial >> 8;
TMR0H = initial >> 8;
+ TMR0L = initial & 0xff;
T0CON = contword;
Sleep();
b &= ~_LCDPORT_CONT_RS;
b |= _LCDPORT_CONT_RW;
_LCDPORT_CONT_LATCH = b;
+ _ACM1602_TC_WAIT(); // Wait 2.5?us
+
b |= _LCDPORT_CONT_EN; // Send CMD
_LCDPORT_CONT_LATCH = b;
_ACM1602_TC_WAIT(); // Wait 2.5?us
+
d = _LCDPORT_DATA;
+ _ACM1602_TC_WAIT(); // Wait 2.5?us
+
+ b &= ~_LCDPORT_CONT_EN; // Disable EN
+ _LCDPORT_CONT_LATCH = b;
+ _ACM1602_TC_WAIT(); // Wait 2.5?us
+
+ b |= _LCDPORT_CONT_EN; // Disable EN
+ _LCDPORT_CONT_LATCH = b;
+ _ACM1602_TC_WAIT(); // Wait 2.5?us
b &= ~_LCDPORT_CONT_EN; // Disable EN
_LCDPORT_CONT_LATCH = b;
+ _ACM1602_TC_WAIT(); // Wait 2.5?us
b = _LCDPORT_TRIS_DATA;
b &= ~_LCDPORT_READMASK; // Clear mask for Tristate, direction = write.
_LCDPORT_TRIS_DATA = b;
+ _ACM1602_TC_WAIT(); // Wait 2.5?us
if((d & _LCDPORT_BUSYMASK) != 0){
d = 0xff; // BUSY
_ACM1602_TC_WAIT();
// Lower NIBBLE
- if(busyflag != 0) lcd_waitbusy(addr, 0);
+// if(busyflag != 0) lcd_waitbusy(addr, 0);
d = _LCDPORT_TRIS_CONT;
d &= ~_LCDPORT_READMASK; // Clear mask for Tristate, direction = write.
_LCDPORT_TRIS_CONT = d;
_ACM1602_TC_WAIT(); // Wait 2.5?us
b |= _LCDPORT_CONT_EN;
_LCDPORT_CONT_LATCH = b;
+
_ACM1602_TC_WAIT(); // Wait 2.5?us
b &= ~_LCDPORT_CONT_EN; // Disable EN
_LCDPORT_CONT_LATCH = b;
b &= ~(_LCDPORT_CONT_RS | _LCDPORT_CONT_RW | _LCDPORT_CONT_EN); // RS='0',RW='0'
b |= h;
_LCDPORT_CONT_LATCH = b;
+ _ACM1602_TC_WAIT(); // Wait 2.5?us
b |= _LCDPORT_CONT_EN; // Send CMD
_LCDPORT_CONT_LATCH = b;
b = _LCDPORT_CONT_LATCH;
b &= ~(_LCDPORT_CONT_RS | _LCDPORT_CONT_RW | _LCDPORT_CONT_EN | 0xf0);
_LCDPORT_CONT_LATCH = b;
-
- //_LCDPORT_TRIS_DATA = 0x00; // OUT
- //_LCDPORT_LATCH_DATA = 0x00;
+ // _LCDPORT_TRIS_DATA = 0x00; // OUT
+ // _LCDPORT_LATCH_DATA = 0x00;
#else
b = _LCDPORT_TRIS_CONT;
b &= ~(_LCDPORT_CONT_RS | _LCDPORT_CONT_RW | _LCDPORT_CONT_EN);
lcd_waitbusy(addr, 0);
d = _LCDPORT_TRIS_CONT;
- d &= ~_LCDPORT_READMASK; // Clear mask for Tristate, direction = write.
+ d &= ~(_LCDPORT_READMASK | _LCDPORT_CONT_RW | _LCDPORT_CONT_EN | _LCDPORT_CONT_RS); // Clear mask for Tristate, direction = write.
+// d = 0;
_LCDPORT_TRIS_CONT = d;
+ _ACM1602_TC_WAIT(); // Wait 2.5?us
// Send high nibble
b = _LCDPORT_CONT_LATCH;
b &= ~_LCDPORT_CONT_EN; // Disable EN
_LCDPORT_CONT_LATCH = b;
- _ACM1602_TC_WAIT();
-
- lcd_waitbusy(addr, 0);
- d = _LCDPORT_TRIS_CONT;
- d &= ~_LCDPORT_READMASK; // Clear mask for Tristate, direction = write.
- _LCDPORT_TRIS_CONT = d;
+ _ACM1602_SHORT_WAIT();
- b = _LCDPORT_CONT_LATCH;
+// lcd_waitbusy(addr, 0);
b &= ~(_LCDPORT_CONT_RW | 0xf0 | _LCDPORT_CONT_EN); // DATA=blank,RW='0'
b |= _LCDPORT_CONT_RS; // RS='1"
b |= l;
- _LCDPORT_CONT_LATCH = b;
- _ACM1602_TC_WAIT(); // Wait 2.5?us
+// _LCDPORT_CONT_LATCH = b;
+// _ACM1602_TC_WAIT(); // Wait 2.5?us
b |= _LCDPORT_CONT_EN;
_LCDPORT_CONT_LATCH = b; // Do low write.
b &= ~_LCDPORT_CONT_EN; // Disable EN
_LCDPORT_CONT_LATCH = b;
- _ACM1602_SHORT_WAIT();
+ _ACM1602_TC_WAIT(); // Wait 2.5?us
+
#else
lcd_waitbusy(addr, 0);
void acm1602_cls(unsigned char addr)
{
sendcmd(addr, 0x01, 0xff);
- _ACM1602_LONG_WAIT(); // Wait 5ms
+ _ACM1602_LONG_LONG_WAIT(); // Wait 5ms
}
void acm1602_setdataramaddress(unsigned char addr, unsigned char pos)
void acm1602_home(unsigned char addr)
{
sendcmd(addr, 0x02, 0xff);
- _ACM1602_LONG_WAIT(); // Wait 5ms
+ _ACM1602_LONG_LONG_WAIT(); // Wait 5ms
}
void acm1602_printf(unsigned char addr, const char *fmt, ...)
sendonce(addr, 0x38); // 2lines, 8x10dot fonts.
sendcmd(addr, 0x38, 0x00); // 2lines, 8x10dot fonts.
#else // 4Bit
+ _ACM1602_LONG_LONG_WAIT();
+ sendonce(addr, 0x30); // 2lines, 8x10dot fonts.
+ _ACM1602_SHORT_WAIT();
sendonce(addr, 0x30); // 2lines, 8x10dot fonts.
+ _ACM1602_SHORT_WAIT();
+ sendonce(addr, 0x30); // 2lines, 8x10dot fonts.
+ _ACM1602_SHORT_WAIT();
+ sendonce(addr, 0x20); // 2lines, 8x10dot fonts.
+ _ACM1602_SHORT_WAIT();
// Send twice on 4Bit Mode.
+// sendonce(addr, 0x30); // 2lines, 8x10dot fonts.
sendcmd(addr, 0x28, 0x00); // 2lines, 8x10dot fonts.
- sendcmd(addr, 0x28, 0x00); // 2lines, 8x10dot fonts.
+// sendcmd(addr, 0x28, 0x00); // 2lines, 8x10dot fonts.
#endif
#endif
- sendcmd(addr, 0x0f, 0xff); // Display ON.
- sendcmd(addr, 0b00000110, 0xff); // Cursor increment,not shift.
+// sendcmd(addr, 0x08, 0xff); // Display OFF.
+ sendcmd(addr, 0x0c, 0xff); // Display ON.
+ sendcmd(addr, 0x06, 0xff); // Cursor increment,not shift.
if(cls == 0){
acm1602_home(addr);
} else {
acm1602_cls(addr);
}
+ _ACM1602_LONG_WAIT();
+ //sendcmd(addr, 0x06, 0xff);
}
/*
* st7032 extensions.
// Notes: Master clock = 8MHz(0.125uS)
// Wait 5us
-#define _ACM1602_TC_WAIT() delay10tcy(4)
+#define _ACM1602_TC_WAIT() delay10tcy(40)
// Wait 50us
-#define _ACM1602_SHORT_WAIT() delay100tcy(4)
+#define _ACM1602_SHORT_WAIT() delay100tcy(40)
// Wait 5ms
-#define _ACM1602_LONG_WAIT() delay1ktcy(40)
+#define _ACM1602_LONG_WAIT() delay10ktcy(40)
// Wait 50ms
#define _ACM1602_LONG_LONG_WAIT() delay10ktcy(40)
// Wait 5.5ms
* Config words.
*/
#if defined(pic18f23k22) || defined(pic18f24k22) || defined(pic18f25k22) || defined(pic18f26k22)
-#pragma stack 0x200 256 // Set stack size to 256bytes.
+//#pragma stack 0x200 256 // Set stack size to 256bytes.
#pragma config FOSC=INTIO67,BORV=190,BOREN=ON,PWRTEN=ON
#pragma config WDTEN=ON,WDTPS=32768
#pragma config PBADEN=OFF,MCLRE=EXTMCLR,STVREN=ON,LVP=OFF,DEBUG=ON//,XINST=ON
+//#pragma config PBADEN=OFF,MCLRE=EXTMCLR,STVREN=ON,LVP=OFF//,XINST=ON
#pragma config CP0=OFF,CP1=OFF,CPB=OFF,CPD=OFF
#pragma config WRT0=OFF,WRT1=OFF,WRTB=OFF,WRTC=OFF,WRTD=OFF
#pragma config EBTR0=OFF,EBTR1=OFF,EBTRB=OFF
// For 4xK20 or 2xK20 Series
#if defined(pic18f43k20) || defined(pic18f44k20) || defined(pic18f45k20) || defined(pic18f46k20) || \
defined(pic18f23k20) || defined(pic18f24k20) || defined(pic18f25k20) || defined(pic18f26k20)
-#pragma stack 0x200 256
-#pragma config FOSC=INTIO67,FCMEN=ON,PWRT=ON,BOREN=ON,BORV=22
-#pragma config WDTEN=ON,WDTPS=32768,PBADEN=OFF,LPT1OSC=ON,MCLRE=ON
+//#pragma stack 0x200
+#pragma config FOSC=HS,FCMEN=ON,PWRT=ON,BOREN=ON,BORV=22
+#pragma config WDTEN=ON,WDTPS=32768,PBADEN=OFF,HFOFST=ON,LPT1OSC=OFF,MCLRE=ON
#pragma config STVREN=ON,DEBUG=ON
#pragma config CP0=OFF,CP1=OFF,CP2=OFF,CP3=OFF
#pragma config CPB=OFF,CPD=OFF
T0CON = t0con;
// Read IOKEYS
- readkey_io();
+// readkey_io();
// Clear interrupt flag
tmr0f = INTCON;
- tmr0f &= ~(_TMR0IF);
+ tmr0f &= ~(_TMR0IF | _TMR0IE);
INTCON = tmr0f;
return;
char readchar;
unsigned char input_flag;
unsigned char c;
+ unsigned int i;
#ifdef _LCD_DEBUG
unsigned char power_flag;
#endif
+ OSCCON = _IDLEN & 0b11111100;
+
keyin_init();
keyin_ioinit();
idle_init();
- i2c1_init();
+ //i2c1_init();
_AKC6955_WAIT_125_0MS(); // Wait 125ms
#ifdef _LCD_DEBUG
ui_idlecount = 0xf800;
acm1602_init(0xa0, 1); //Init LCD
-// _AKC6955_WAIT_125_0MS(); // Wait 125ms
+ _AKC6955_WAIT_125_0MS(); // Wait 125ms
_LOCATE(0,0);
printstr("Hello;-)");
-
+ PORTDbits.RD3 = 1;
+ LATDbits.LATD3 = 1;
+
+#if 1
+ i = 10001;
+ do {
+ idle(0xf800);
+ ClrWdt();
+ _LOCATE(0,1);
+ print_numeric_nosupress(i, 5);
+ i = i + 1;
+ }while(1);
+#else
switch(load_eeprom()) {
case 0x01: // No magic-word
idle(0xff80);
#endif
idle(ui_idlecount);
} while(1);
+#endif
}
#
-#Thu Jun 13 16:09:38 JST 2013
+#Sun Jun 16 12:31:30 JST 2013
default.languagetoolchain.dir=/usr/local/bin
default.br-unifei-rmaalmeida-toolchainSDCC-SDCCtoolchain.md5=b67cce1ad75b450308d7806e430931b3
com-microchip-mplab-nbide-embedded-makeproject-MakeProject.md5=8fe1589514540343a5279c082104bce0
<targetDevice>PIC18F45K20</targetDevice>
<targetHeader></targetHeader>
<targetPluginBoard></targetPluginBoard>
- <platformTool>PICkit2PlatformTool</platformTool>
+ <platformTool>PICkit3PlatformTool</platformTool>
<languageToolchain>SDCCToolchain</languageToolchain>
<languageToolchainVersion>3.3.0</languageToolchainVersion>
<platform>2</platform>
<makeCustomizationEnableLongLines>false</makeCustomizationEnableLongLines>
<makeCustomizationNormalizeHexFile>false</makeCustomizationNormalizeHexFile>
</makeCustomizationType>
- <PICkit2PlatformTool>
- <property key="pk2settings.3state" value="false"/>
- <property key="pk2settings.preserveee" value="false"/>
- <property key="pk2settings.setvddvoltage" value=""/>
- <property key="pk2settings.userpgmexec" value="true"/>
- <property key="pk2settings.usetargetpower" value="false"/>
- </PICkit2PlatformTool>
+ <PICkit3PlatformTool>
+ <property key="AutoSelectMemRanges" value="auto"/>
+ <property key="Freeze Peripherals" value="true"/>
+ <property key="SecureSegment.SegmentProgramming" value="FullChipProgramming"/>
+ <property key="ToolFirmwareFilePath"
+ value="Press to browse for a specific firmware version"/>
+ <property key="ToolFirmwareOption.UseLatestFirmware" value="true"/>
+ <property key="hwtoolclock.frcindebug" value="false"/>
+ <property key="memories.aux" value="false"/>
+ <property key="memories.bootflash" value="false"/>
+ <property key="memories.configurationmemory" value="false"/>
+ <property key="memories.eeprom" value="false"/>
+ <property key="memories.flashdata" value="true"/>
+ <property key="memories.id" value="false"/>
+ <property key="memories.programmemory" value="true"/>
+ <property key="memories.programmemory.end" value="0x7fff"/>
+ <property key="memories.programmemory.start" value="0x0"/>
+ <property key="poweroptions.powerenable" value="true"/>
+ <property key="programmertogo.imagename" value=""/>
+ <property key="programoptions.eraseb4program" value="true"/>
+ <property key="programoptions.pgmspeed" value="2"/>
+ <property key="programoptions.preserveeeprom" value="false"/>
+ <property key="programoptions.preserveprogramrange" value="false"/>
+ <property key="programoptions.preserveprogramrange.end" value="0x7fff"/>
+ <property key="programoptions.preserveprogramrange.start" value="0x0"/>
+ <property key="programoptions.preserveuserid" value="false"/>
+ <property key="programoptions.usehighvoltageonmclr" value="false"/>
+ <property key="programoptions.uselvpprogramming" value="false"/>
+ <property key="voltagevalue" value="3.25"/>
+ </PICkit3PlatformTool>
<sdcc>
<property key="V-show-commands-compiler" value="true"/>
<property key="Werror" value="false"/>
<defaultConf>0</defaultConf>
<confs>
<conf name="default" type="2">
- <platformToolSN></platformToolSN>
+ <platformToolSN>:=MPLABCommUSB:=04D8:=900A:=0002:=Microchip Technology Inc.:=PICkit 3:=DEFAULT_PK3 :=x:=en</platformToolSN>
<languageToolchainDir>/usr/local/bin</languageToolchainDir>
<mdbdebugger version="1">
<placeholder1>place holder 1</placeholder1>
void print_numeric_nosupress(unsigned int data, unsigned char digit)
{
- unsigned char i;
+ unsigned int i;
unsigned char c;
int ref = 10;
int div = 1;
if(digit == 0) return;
if(digit >= 5) digit = 5;
- _CURSOR_LEFT();
- for(i = 0; i < digit; i++){
- c = (data % ref) / div + '0';
- _PUTCHAR(c);
- ref *= 10;
+ if(digit == 5){
+ i = data / 10000;
+ data = data % 10000;
+ _PUTCHAR(i + '0');
+ digit--;
+ }
+ if(digit == 4){
+ i = data / 1000;
+ data = data % 1000;
+ _PUTCHAR(i + '0');
+ digit--;
+ }
+ if(digit == 3){
+ i = data / 100;
+ data = data % 100;
+ _PUTCHAR(i + '0');
+ digit--;
+ }
+ if(digit == 2){
+ i = data / 10;
+ data = data % 10;
+ _PUTCHAR(i + '0');
+ digit--;
+ }
+ if(digit == 1){
+ i = data;
+ _PUTCHAR(i + '0');
+ digit--;
}
- _CURSOR_RIGHT();
}
/*
* Read Numeric(int)