microsoft odbc drivermanager SQLColAttribute SQL_INVALID_HANDLE - odbc

I'm getting SQL_INVALID_HANDLE error when calling SQLColAttribute from an application (trying to communicate with self developed odbc driver) I don't know why the handle is stated an invalid handle, since its a simple struct, which is still valid at runtime, ive checked it. The driver is a non unicode driver and im using it from a non unicode test application.
The driver also manages to set (log from the driver)
SQLGetStmtAttr called:
Attribute to set is: SQL_ATTR_APP_ROW_DESC
SQLGetStmtAttr called:
Attribute to set is: SQL_ATTR_APP_PARAM_DESC
SQLGetStmtAttr called:
Attribute to set is: SQL_ATTR_IMP_ROW_DESC
SQLGetStmtAttr called:
Attribute to set is: SQL_ATTR_IMP_PARAM_DESC
properly before calling sqlprepare
the driver manager log:
ODBC_Test 2210-151c ENTER SQLAllocHandle
SQLSMALLINT 1 <SQL_HANDLE_ENV>
SQLHANDLE 0x00000000
SQLHANDLE * 0x002EFCC0
ODBC_Test 2210-151c EXIT SQLAllocHandle with return code 0 (SQL_SUCCESS)
SQLSMALLINT 1 <SQL_HANDLE_ENV>
SQLHANDLE 0x00000000
SQLHANDLE * 0x002EFCC0 ( 0x003541C8)
ODBC_Test 2210-151c ENTER SQLSetEnvAttr
SQLHENV 0x003541C8
SQLINTEGER 200 <SQL_ATTR_ODBC_VERSION>
SQLPOINTER 3 <SQL_OV_ODBC3>
SQLINTEGER 0
ODBC_Test 2210-151c EXIT SQLSetEnvAttr with return code 0 (SQL_SUCCESS)
SQLHENV 0x003541C8
SQLINTEGER 200 <SQL_ATTR_ODBC_VERSION>
SQLPOINTER 3 <SQL_OV_ODBC3>
SQLINTEGER 0
ODBC_Test 2210-151c ENTER SQLAllocHandle
SQLSMALLINT 2 <SQL_HANDLE_DBC>
SQLHANDLE 0x003541C8
SQLHANDLE * 0x002EFCA8
ODBC_Test 2210-151c EXIT SQLAllocHandle with return code 0 (SQL_SUCCESS)
SQLSMALLINT 2 <SQL_HANDLE_DBC>
SQLHANDLE 0x003541C8
SQLHANDLE * 0x002EFCA8 ( 0x00354250)
ODBC_Test 2210-151c ENTER SQLConnectW
HDBC 0x00354250
WCHAR * 0x00352EB8 [ 5] "dsn01"
SWORD 5
WCHAR * 0x55128B34 [ -3] "******\ 0"
SWORD -3
WCHAR * 0x55128B34 [ -3] "******\ 0"
SWORD -3
ODBC_Test 2210-151c EXIT SQLConnectW with return code 0 (SQL_SUCCESS)
HDBC 0x00354250
WCHAR * 0x00352EB8 [ 5] "dsn01"
SWORD 5
WCHAR * 0x55128B34 [ -3] "******\ 0"
SWORD -3
WCHAR * 0x55128B34 [ -3] "******\ 0"
SWORD -3
ODBC_Test 2210-151c ENTER SQLAllocHandle
SQLSMALLINT 3 <SQL_HANDLE_STMT>
SQLHANDLE 0x00354250
SQLHANDLE * 0x002EF6F8
ODBC_Test 2210-151c EXIT SQLAllocHandle with return code 0 (SQL_SUCCESS)
SQLSMALLINT 3 <SQL_HANDLE_STMT>
SQLHANDLE 0x00354250
SQLHANDLE * 0x002EF6F8 ( 0x00355790)
ODBC_Test 2210-151c ENTER SQLPrepare
HSTMT 0x00355790
UCHAR * 0x00DB89C8 [ 72] "select COUNTRYFR,CITYFROM,CITYTO from SPFLI where CITYFROM EQ 'NEW YORK'"
SDWORD 72
ODBC_Test 2210-151c EXIT SQLPrepare with return code 0 (SQL_SUCCESS)
HSTMT 0x00355790
UCHAR * 0x00DB89C8 [ 72] "select COUNTRYFR,CITYFROM,CITYTO from SPFLI where CITYFROM EQ 'NEW YORK'"
SDWORD 72
ODBC_Test 2210-151c ENTER SQLColAttribute
SQLHSTMT 0x00355790
SQLSMALLINT 1
SQLSMALLINT 14 <SQL_DESC_TYPE_NAME>
SQLPOINTER 0x002EF6B0
SQLSMALLINT 50
SQLSMALLINT * 0x002EF6A4
SQLPOINTER 0x00000000 (NYI)
ODBC_Test 2210-151c ENTER SQLColAttribute
SQLHSTMT 0x00C05200
SQLSMALLINT 1
SQLSMALLINT 14 <SQL_DESC_TYPE_NAME>
SQLPOINTER 0x002EF6B0
SQLSMALLINT 50
SQLSMALLINT * 0x002EF6A4
SQLPOINTER 0x00000000 (NYI)
ODBC_Test 2210-151c EXIT SQLColAttribute with return code -2 (SQL_INVALID_HANDLE)
SQLHSTMT 0x00C05200
SQLSMALLINT 1
SQLSMALLINT 14 <SQL_DESC_TYPE_NAME>
SQLPOINTER 0x002EF6B0
SQLSMALLINT 50
SQLSMALLINT * 0x002EF6A4
SQLPOINTER 0x00000000 (NYI)
ODBC_Test 2210-151c EXIT SQLColAttribute with return code -2 (SQL_INVALID_HANDLE)
SQLHSTMT 0x00355790
SQLSMALLINT 1
SQLSMALLINT 14 <SQL_DESC_TYPE_NAME>
SQLPOINTER 0x002EF6B0
SQLSMALLINT 50
SQLSMALLINT * 0x002EF6A4
SQLPOINTER 0x00000000 (NYI)
The test program is pretty simple:
SQLHANDLE hEnv ;
SQLAllocHandle( SQL_HANDLE_ENV, SQL_NULL_HANDLE, &hEnv ) ;
SQLSetEnvAttr( hEnv, SQL_ATTR_ODBC_VERSION, (void*)SQL_OV_ODBC3, 0 ) ;
SQLHANDLE hConn ;
SQLAllocHandle( SQL_HANDLE_DBC, hEnv, &hConn );
SQLCHAR* dsnName = (SQLCHAR*)"dsn01" ; // MUST BE THE SAME
SQLCHAR* userid = (SQLCHAR*)"nodata\0";
SQLCHAR* password = (SQLCHAR*)"nodata\0";
SQLConnect(
hConn,
dsnName,
5,
userid,
SQL_NTS,
password,
SQL_NTS);
HSTMT hStmt ;
SQLAllocHandle( SQL_HANDLE_STMT, hConn, &hStmt ) ;
SQLCHAR* query = (SQLCHAR*)"select COUNTRYFR,CITYFROM,CITYTO from SPFLI where CITYFROM EQ 'NEW YORK'";
SQLPrepare(hStmt,query,strlen((const char*)query));
SQLCHAR TypeName[50];
SQLSMALLINT TypeNameLen;
SQLColAttribute((SQLHSTMT)hStmt,1,SQL_DESC_TYPE_NAME,TypeName, sizeof(TypeName),&TypeNameLen,NULL);
Anyone knows what can cause SQLColAttribute to give back SQL_INVALID_HANDLE ? I've read msdn but nothing useful was there.

You allocated a statement handle which is 0x00355790. You prepared it. It all goes wrong as you say when you call SQLColAttribute. The log suggests that SQLColAttribute was called correctly with the statement handle but then (your driver?) called SQLColAttribute again with a different handle. My guess is you've got a function name clash in your driver.

See this declaration in sqlucode.h :
// UNICODE versions
#ifdef _WIN64
SQLRETURN SQL_API SQLColAttributeW
(
SQLHSTMT hstmt,
SQLUSMALLINT iCol,
SQLUSMALLINT iField,
_Out_writes_bytes_opt_(cbDescMax)
SQLPOINTER pCharAttr,
SQLSMALLINT cbDescMax,
_Out_opt_
SQLSMALLINT *pcbCharAttr,
_Out_opt_
SQLLEN *pNumAttr
);
#else
SQLRETURN SQL_API SQLColAttributeW(
SQLHSTMT hstmt,
SQLUSMALLINT iCol,
SQLUSMALLINT iField,
_Out_writes_bytes_opt_(cbDescMax)
SQLPOINTER pCharAttr,
SQLSMALLINT cbDescMax,
_Out_opt_
SQLSMALLINT *pcbCharAttr,
_Out_opt_
SQLPOINTER pNumAttr);
#endif
and understand how difficult it is
> (for me) to avoid the function name clash in both cases (x64/x86)
> (for microsoft) to write correct doc

Related

Strange serial prints - ESP8266 Wifi Web server

I am working on a web server project on the ESP8266, using Platform and the Arduino libraries.
My dependencies include ESP8266WiFi, ESP8266WebServer, tzapu/WiFiManager.
In my serial monitor, I keep seeing strange prints I did not put there myself. Here is an example :
:wr 57 0
:wrc 57 57 0
:wr 16 0
:wrc 16 16 0
:wr 17 0
:wrc 17 17 0
:wr 669 0
:wrc 669 669 0
:wr 269 0
:wrc 269 269 0
:wr 9 0
:wrc 9 9 0
:ack 57
:ack 536
:ack 444
:close
Does anybody know what these are, where they come from, and how to get rid of them ?
Here is part of my code (setup() in in main.cpp)
void setup(void) {
/* Set up logger */
gLogger = &Logger::instance();
/* Init relay */
gRelay = new elec::Relay(LED_DIO, elec::RELAY_MODE_NORMAL);
/* Init Switch */
gSwitch = new elec::Switch(SWITCH_DIO);
/* Init WiFi manager */
gWiFiMgr = new WiFiManager;
/** Set callback that gets called when connecting
* to previous WiFi fails,
* and enters Access Point mode */
gWiFiMgr->setAPCallback(configModeCallback);
/* Disable debug mode for the WiFiManager */
gWiFiMgr->setDebugOutput(false);
if(!gWiFiMgr->autoConnect(AP_NAME, AP_PASSWD)) {
*gLogger << "[ERROR] Failed to connect to WiFi !" << endlog;
ESP.reset();
delay(1000U);
}
*gLogger << "[BOOT ] Successfully connected to " << WiFi.SSID() << endlog;
*gLogger << "[BOOT ] IPv4 Address : " << WiFi.localIP().toString() << endlog;
/* Set up web server */
gServer = new WiFiServer(80U);
gServer->begin();
/* End of setup */
*gLogger << "[BOOT ] System booted !" << endlog;
}
In my case this was due to enabling "Debug Level: CORE" in Arduino IDE. Once I set it to None, these stopped.

Jar to exe using NSIS

so I seeking for a program (which is free) that will allow me to make from jar to exe with wrapping JRE also... til now I used Launch4J and I tried out others also but I found NSIS which is much more powerful and i think will fit what I'm looking for, but I'm having problems with defining CLASSPATH and CLASS.
Here's the code:
Name "Tool"
Caption "Internal"
Icon "UIT.ico"
OutFile "Tool.exe"
VIAddVersionKey "ProductName" "Tool"
VIAddVersionKey "Comments" "Internal"
VIAddVersionKey "CompanyName" ""
VIAddVersionKey "LegalTrademarks" ""
VIAddVersionKey "LegalCopyright" ""
VIAddVersionKey "FileDescription" "Tool"
VIAddVersionKey "FileVersion" "3.0.1934"
VIProductVersion 3.0.1934"
!define CLASSPATH "ApplicationTool.jar"
!define CLASS "v3build1934"
!define PRODUCT_NAME "Tool"
; Definitions for Java 8.0
!define JRE_VERSION "8.0"
!define JRE_URL "http://javadl.sun.com/webapps/download/AutoDL?BundleId=24936&/jre-6u10-windows-i586-p.exe"
;!define JRE_VERSION "8.0"
;!define JRE_URL "http://javadl.sun.com/webapps/download/AutoDL?BundleId=22933&/jre-1_5_0_16-windows-i586-p.exe"
; use javaw.exe to avoid dosbox.
; use java.exe to keep stdout/stderr
!define JAVAEXE "javaw.exe"
RequestExecutionLevel user
SilentInstall silent
AutoCloseWindow true
ShowInstDetails nevershow
!include "FileFunc.nsh"
!insertmacro GetFileVersion
!insertmacro GetParameters
!include "WordFunc.nsh"
!insertmacro VersionCompare
!include "UAC.nsh"
Section ""
Call GetJRE
Pop $R0
; change for your purpose (-jar etc.)
${GetParameters} $1
StrCpy $0 '"$R0" -classpath "${CLASSPATH}" ${CLASS} $1'
SetOutPath $EXEDIR
Exec $0
SectionEnd
; returns the full path of a valid java.exe
; looks in:
; 1 - .\jre directory (JRE Installed with application)
; 2 - JAVA_HOME environment variable
; 3 - the registry
; 4 - hopes it is in current dir or PATH
Function GetJRE
Push $R0
Push $R1
Push $2
; 1) Check local JRE
CheckLocal:
ClearErrors
StrCpy $R0 "$EXEDIR\pkg\bin\${JAVAEXE}"
IfFileExists $R0 JreFound
; 2) Check for JAVA_HOME
CheckJavaHome:
ClearErrors
ReadEnvStr $R0 "JAVA_HOME"
StrCpy $R0 "$R0\bin\${JAVAEXE}"
IfErrors CheckRegistry
IfFileExists $R0 0 CheckRegistry
Call CheckJREVersion
IfErrors CheckRegistry JreFound
; 3) Check for registry
CheckRegistry:
ClearErrors
ReadRegStr $R1 HKLM "SOFTWARE\JavaSoft\Java Runtime Environment" "CurrentVersion"
ReadRegStr $R0 HKLM "SOFTWARE\JavaSoft\Java Runtime Environment\$R1" "JavaHome"
StrCpy $R0 "$R0\bin\${JAVAEXE}"
IfErrors DownloadJRE
IfFileExists $R0 0 DownloadJRE
Call CheckJREVersion
IfErrors DownloadJRE JreFound
DownloadJRE:
Call ElevateToAdmin
MessageBox MB_ICONINFORMATION "${PRODUCT_NAME} uses Java Runtime Environment ${JRE_VERSION}, it will now be downloaded and installed."
StrCpy $2 "$TEMP\Java Runtime Environment.exe"
nsisdl::download /TIMEOUT=30000 ${JRE_URL} $2
Pop $R0 ;Get the return value
StrCmp $R0 "success" +3
MessageBox MB_ICONSTOP "Download failed: $R0"
Abort
ExecWait $2
Delete $2
ReadRegStr $R1 HKLM "SOFTWARE\JavaSoft\Java Runtime Environment" "CurrentVersion"
ReadRegStr $R0 HKLM "SOFTWARE\JavaSoft\Java Runtime Environment\$R1" "JavaHome"
StrCpy $R0 "$R0\bin\${JAVAEXE}"
IfFileExists $R0 0 GoodLuck
Call CheckJREVersion
IfErrors GoodLuck JreFound
; 4) wishing you good luck
GoodLuck:
StrCpy $R0 "${JAVAEXE}"
; MessageBox MB_ICONSTOP "Cannot find appropriate Java Runtime Environment."
; Abort
JreFound:
Pop $2
Pop $R1
Exch $R0
FunctionEnd
; Pass the "javaw.exe" path by $R0
Function CheckJREVersion
Push $R1
; Get the file version of javaw.exe
${GetFileVersion} $R0 $R1
${VersionCompare} ${JRE_VERSION} $R1 $R1
; Check whether $R1 != "1"
ClearErrors
StrCmp $R1 "1" 0 CheckDone
SetErrors
CheckDone:
Pop $R1
FunctionEnd
; Attempt to give the UAC plug-in a user process and an admin process.
Function ElevateToAdmin
UAC_Elevate:
!insertmacro UAC_RunElevated
StrCmp 1223 $0 UAC_ElevationAborted ; UAC dialog aborted by user?
StrCmp 0 $0 0 UAC_Err ; Error?
StrCmp 1 $1 0 UAC_Success ;Are we the real deal or just the wrapper?
Quit
UAC_ElevationAborted:
# elevation was aborted, run as normal?
MessageBox MB_ICONSTOP "This installer requires admin access, aborting!"
Abort
UAC_Err:
MessageBox MB_ICONSTOP "Unable to elevate, error $0"
Abort
UAC_Success:
StrCmp 1 $3 +4 ;Admin?
StrCmp 3 $1 0 UAC_ElevationAborted ;Try again?
MessageBox MB_ICONSTOP "This installer requires admin access, try again"
goto UAC_Elevate
FunctionEnd
What do i need to put in those 2 or should I move the script somewhere else for example where the netbeans project is ???
You can set environment variables for the NSIS process and child processes by calling SetEnvironmentVariable:
System::Call 'Kernel32::SetEnvironmentVariable(t "CLASSPATH", t "c:\some\path\you\got\from\the\registry")'

How to list network devices in NASM (custom OS)

I have a custom, DOS-like OS built in NASM completely (no C code). It is very modest (it does have a FAT file system, few apps, is in real mode, etc.) I want to write a command that will list all the network devices (network cards) that are currently connected.
My assumptions go like this: I will need to write a driver for the network card (I'd put it manually inside kernel for simplicity, so dynamic loading would NOT exist), but it would be enough for that driver to just provide the name of the card, the network card wouldn't actually need to work. How do I tell the OS to connect that function to precisely that one network card? This is what I'm in the blue about, I have no idea how the OS usually matches a piece of hardware to code (its driver(s)).
Since it appears from your comments that you have Dosbox supporting an NE2000 card then the code below should detect the presence of an NE2000 card (A port base of 0x300 is assumed). The code is a DOS COM program I wrote and should be compilable with a command like nasm ne2kchk.asm -fbin -o ne2kchk.com
NS_DATAPORT EQU 0x10 ; NatSemi-defined port window offset.
NE_DATAPORT EQU 0x10 ; NatSemi-defined port window offset.
NS_RESET EQU 0x1f ; Issue a read to reset, a write to clear.
NE1SM_START_PG EQU 0x20 ; First page of TX buffer
NE1SM_STOP_PG EQU 0x40 ; Last page +1 of RX ring
NESM_START_PG EQU 0x40 ; First page of TX buffer
NESM_STOP_PG EQU 0x80 ; Last page +1 of RX ring
E8390_CMD EQU 0x00 ; The command register (for all pages)
E8390_STOP EQU 0x01 ; Stop and reset the chip
E8390_START EQU 0x02 ; Start the chip, clear reset
E8390_RREAD EQU 0x08 ; Remote read
E8390_NODMA EQU 0x20 ; Remote DMA
E8390_PAGE0 EQU 0x00 ; Select page chip registers
E8390_PAGE1 EQU 0x40 ; using the two high-order bits
E8390_PAGE2 EQU 0x80
E8390_PAGE3 EQU 0xC0 ; Page 3 is invalid on the real 8390.
E8390_RXOFF EQU 0x20 ; EN0_RXCR: Accept no packets
E8390_TXOFF EQU 0x02 ; EN0_TXCR: Transmitter off
; Page 0 register offsets.
EN0_CLDALO EQU 0x01 ; Low byte of current local dma addr RD
EN0_STARTPG EQU 0x01 ; Starting page of ring bfr WR
EN0_CLDAHI EQU 0x02 ; High byte of current local dma addr RD
EN0_STOPPG EQU 0x02 ; Ending page +1 of ring bfr WR
EN0_BOUNDARY EQU 0x03 ; Boundary page of ring bfr RD WR
EN0_TSR EQU 0x04 ; Transmit status reg RD
EN0_TPSR EQU 0x04 ; Transmit starting page WR
EN0_NCR EQU 0x05 ; Number of collision reg RD
EN0_TCNTLO EQU 0x05 ; Low byte of tx byte count WR
EN0_FIFO EQU 0x06 ; FIFO RD
EN0_TCNTHI EQU 0x06 ; High byte of tx byte count WR
EN0_ISR EQU 0x07 ; Interrupt status reg RD WR
EN0_CRDALO EQU 0x08 ; low byte of current remote dma address RD
EN0_RSARLO EQU 0x08 ; Remote start address reg 0
EN0_CRDAHI EQU 0x09 ; high byte, current remote dma address RD
EN0_RSARHI EQU 0x09 ; Remote start address reg 1
EN0_RCNTLO EQU 0x0a ; Remote byte count reg WR
EN0_RCNTHI EQU 0x0b ; Remote byte count reg WR
EN0_RSR EQU 0x0c ; rx status reg RD
EN0_RXCR EQU 0x0c ; RX configuration reg WR
EN0_TXCR EQU 0x0d ; TX configuration reg WR
EN0_COUNTER0 EQU 0x0d ; Rcv alignment error counter RD
EN0_DCFG EQU 0x0e ; Data configuration reg WR
EN0_COUNTER1 EQU 0x0e ; Rcv CRC error counter RD
EN0_IMR EQU 0x0f ; Interrupt mask reg WR
EN0_COUNTER2 EQU 0x0f ; Rcv missed frame error counter RD
PORT_BASE EQU 0x300 ; Default base port
[BITS 16]
org 0x100
section .text
start:
push cs
pop ds
; Probe for NE2000 card
; Try non destructive test first
mov dx, PORT_BASE+E8390_CMD
in al, dx
cmp al, 0xff
jz .s_notfound
; Attempt potentially destuctive tests
mov al, E8390_NODMA | E8390_PAGE1 | E8390_STOP
mov dx, PORT_BASE+E8390_CMD
out dx, al ; Receive alignment error counter
mov dx, PORT_BASE+EN0_COUNTER0
in al, dx
mov cl, al ; Save to REGD (CL)
mov al, 0xff
out dx, al
mov al, E8390_NODMA | E8390_PAGE0
mov dx, PORT_BASE+E8390_CMD
out dx, al
mov dx, PORT_BASE+EN0_COUNTER0
in al, dx ; Clear the counter by reading.
test al, al
jz .s_found ; If al is clear then card was found
; Card not found
.s_notfound:
xchg al, cl ; Temporarily save al to avoid clobber
out dx, al
mov ah, 0x09
mov dx, notfound_str
int 0x21
xchg al, cl ; Restore al. al = error value to return
jmp .s_exit
; Card found
.s_found:
mov ah, 0x09
mov dx, found_str
int 0x21
xor al, al ; Clear the error code
; exit with al = errcode
.s_exit:
mov ah, 0x4C
int 0x21
notfound_str db "NE2000 not found", 0x0a, 0x0d, "$"
found_str db "NE2000 found", 0x0a, 0x0d, "$"
The code above is an adaptation of "C" code that I found in the Debian nictool code available here . It can be found in the file ne2k-diags.c. It seems more information (datasheets) are available for the rtl8019 which is a clone of the NE2000. The 8390NIC that is at the heart of these devices is documented here. The 8390 documentation discusses how to send and receive data. An excerpt of the "C" code that I based mine on was:
printf("Checking the ethercard at %#3x.\n", port_base);
{ int regd;
long ioaddr = port_base;
outb_p(E8390_NODMA+E8390_PAGE1+E8390_STOP, ioaddr + E8390_CMD);
regd = inb_p(ioaddr + 0x0d);
printk(" Receive alignment error counter (%#lx) is %2.2x\n",
ioaddr + 0x0d, regd);
outb_p(0xff, ioaddr + 0x0d);
outb_p(E8390_NODMA+E8390_PAGE0, ioaddr + E8390_CMD);
inb_p(ioaddr + EN0_COUNTER0); /* Clear the counter by reading. */
if (inb_p(ioaddr + EN0_COUNTER0) != 0) {
outb(regd, ioaddr + 0x0d); /* Restore the old values. */
printk(" Failed initial NE2000 probe, value %2.2x.\n",
inb(ioaddr + EN0_COUNTER0));
} else
printk(" Passed initial NE2000 probe, value %2.2x.\n",
inb(ioaddr + EN0_COUNTER0));
}
The code above is the initial probe but there is more "C" code in the same file that tries to detect some of the specific variants and query the card signature.

PIC184550: Program seems to terminate at call function

I'm writing a program that will blink red, yellow, and green LEDs off and on to match the function of a traffic light. However, when I run it in the debugger and step through (I am using MPLAB X IDE), it seems to stop after calling the function 'LOOP1'. The value reflected in PORTD is the value it should hold after completion of LOOP1, rather than after completion of LOOP6. Any ideas?
list p=18f4550, r=DEC
#include <p18f4550.inc>
CONFIG LVP=OFF
CONFIG WDT=OFF
CONFIG MCLRE=OFF
CONFIG FOSC = INTOSCIO_EC
ORG 0x00
CBLOCK 0
DELAY1:1
DELAY2:1
COUNTER:1
ENDC
START:
CLRF TRISD
CLRF PORTD
CLRF COUNTER
CLRF DELAY1
CLRF DELAY2
MOVLW 0x00
PRIMARYLOOP:
CALL LOOP1
CALL LOOP2
CALL LOOP3
CALL LOOP4
CALL LOOP5
CALL LOOP6
GOTO PRIMARYLOOP
LOOP1:
MOVLW b'00010010'
MOVWF PORTD
MOVLW 0x01
MOVWF COUNTER
CALL DELAYMAIN
RETURN
LOOP2:
MOVLW b'01000010'
MOVWF PORTD
MOVLW 0x05
MOVWF COUNTER
CALL DELAYMAIN
RETURN
LOOP3:
MOVLW b'00100010'
MOVWF PORTD
MOVLW 0x03
MOVWF COUNTER
CALL DELAYMAIN
RETURN
LOOP4:
MOVLW b'00010010'
MOVWF PORTD
MOVLW 0x01
MOVWF COUNTER
CALL DELAYMAIN
RETURN
LOOP5:
MOVLW b'01000010'
MOVWF PORTD
MOVLW 0x05
MOVWF COUNTER
CALL DELAYMAIN
RETURN
LOOP6:
MOVLW b'00100010'
MOVWF PORTD
MOVLW 0x03
MOVWF COUNTER
CALL DELAYMAIN
RETURN
DELAYMAIN:
DECFSZ DELAY1,1
GOTO DELAYMAIN
DECFSZ DELAY2,1
GOTO DELAYMAIN
DECFSZ COUNTER,0,0
RETURN
END
You're skipping the return instruction in DELAYMAIN, causing execution to go beyond the program. The rest of memory likely contains NOP instructions, so control will continue until the PC wraps around to 0 and the program restarts.
Simply add the missing GOTO (or BRA) instruction after the last DECFSZ and it should get to the second loop. You also need to change the destination of that DECFSZ to write to the register, or it will never finish when COUNTER > 1.

Microchip MPLABX ADC simulation issue: ADC-W101: Selected channel is configured as digital IO

I'm trying to simulate the following program with MPLAB X simulator, but the ADC seems not working. I have attached a stimulus file with '0303' values to the ADRESL register but I have no read and in the simulator console i got a warning "ADC-W101: Selected channel is configured as digital IO. The channel selected:0.". Moreover once set, the ADCON0 GO bit doesn't clear, even if the ADIF is triggered. The pic is a 16f88.
Is it a problem of the MPLAB X simulator? I've checked the limitations of MPLABX sim with the 16f88 but there is nothing about the ADC.
processor 16f88
include <P16F88.INC>
errorlevel 0, -302 ; suppress messages about bank selection
__CONFIG _CONFIG1, _WDT_OFF & _FOSC_INTOSCIO & _MCLR_ON & _LVP_OFF
udata
LIGHT_SENS res 2
TEMP_W res 1
TEMP_STATUS res 1
TEMP_PCLATH res 1
FLAGS res 1
TIME1 equ h'00000'
ADC equ h'00001'
reset code 0x00
pagesel main
goto main
isr code 0x04
_isr_entry:
movwf TEMP_W
swapf STATUS, W
clrf STATUS
movwf TEMP_STATUS
movf PCLATH, W
movwf TEMP_PCLATH
clrf PCLATH
_isr_test_tmr0:
banksel INTCON
btfss INTCON, TMR0IF
goto _isr_test_adc
_tmr0_isr:
_tmr0_isr_entry:
banksel TMR0
movlw d'100'
movwf TMR0
bsf FLAGS, TIME1
_tmr0_isr_exit:
banksel INTCON
bcf INTCON, TMR0IF
_isr_test_adc:
banksel PIR1
btfss PIR1, ADIF
goto _isr_exit
_adc_isr:
_adc_isr_entry:
banksel FLAGS
bsf FLAGS, ADC
_adc_isr_exit:
banksel PIR1
bcf PIR1, ADIF
_isr_exit:
movf TEMP_PCLATH, W
movwf PCLATH
swapf TEMP_STATUS, W
movwf STATUS
swapf TEMP_W, F
swapf TEMP_W, W
retfie
;===============================================================================
main code
main
_setup_oscillator:
banksel OSCCON
movlw b'01100000' ; 4 MHz Internal Oscillator Clock Speed
movwf OSCCON
clrf OSCTUNE ; Center frequency
;===============================================================================
_setup_pin:
banksel PORTA
clrf PORTA ; clears the latch on PORTA before configuring it
banksel PORTB
clrf PORTB ; clears the latch on PORTB before configuring it
_setup_tmr0:
banksel TMR0
movlw d'100'
movwf TMR0
banksel OPTION_REG
movlw b'11010101' ; Prescaler is assigned to Timer0, rate 1:256, Timer mode
movwf OPTION_REG
bsf INTCON, TMR0IE ; enables Timer0 Overflow Interrupt
_setup_adcs:
banksel TRISA ; set PORTA pin direction
movlw h'01' ; RA0 is analog input
movwf TRISA
banksel ANSEL ; select analog pins
movlw h'01' ; AN0 is analog I/O
movwf ANSEL
banksel ADCON0 ; A/D channel selection
movlw b'10000000' ; channel AN0 selected
movwf ADCON0
banksel ADCON1 ; voltage reference, result justification, A/D clock
movlw b'10000000' ; right just, Vdd/Vss ref
movwf ADCON1
banksel ADCON0
bsf ADCON0, ADON
banksel PIE1
bsf PIE1, ADIE
banksel PIR1 ; enables A/DC interrupt
bcf PIR1, ADIF
banksel INTCON
bsf INTCON, GIE ; enables global interrupt
bsf INTCON, PEIE ; enables peripheral interrupt
_setup_application:
clrf FLAGS
_main_loop:
call CheckAdc
_main_loop_exit:
clrf FLAGS
goto _main_loop
;===============================================================================
CheckAdc
_CheckAdc_entry:
banksel FLAGS
btfss FLAGS, ADC ; tests if ADC is ready
goto _CheckAdc_restart
banksel ADRESL
movf ADRESL, W
banksel LIGHT_SENS
movwf LIGHT_SENS
banksel ADRESH
movf ADRESH, W
banksel LIGHT_SENS
movwf LIGHT_SENS+1
_CheckAdc_restart:
banksel FLAGS
btfss FLAGS, TIME1 ; tests if 1ms timer run out
goto _CheckAdc_exit
banksel ADCON0
btfss ADCON0, GO
bsf ADCON0, GO
_CheckAdc_exit:
return
end ; End Of Program

Resources