Thanks!yo2lio wrote:Enjoy!
Additional library for MikroPascal PRO 2009
Re: Additional library for MikroPascal PRO 2009
Ethernet library updated, both ENC28J60 and PIC18F97J60 family.
Now, library can receive UDP broadcast packets and can insert dynamic string variables in HTML code.
1. UDP broadcast
- can be enabled or disabled via udp_broadcast flag.
this flag is default false and can be activated after Eth_Init routine.
- when one UDP broadcast packet is received, this arrive in Eth_UserUDP routine and a new flag broadcast_packet become true. For non broadcast packet, this flag have false state.
2. Dynamic string variables in HTML code
- added a new value for Socket.RAM_ROM, this is 2.
- when Socket[j].RAM_ROM = 2, MCU will search in HTML const after "@" char. This must be followed by two numbers from 00 to 99.
- user must make a table (array[x] of word) with string variables address. When MCU will found "@00" will copy in ETH mem, the string that have start address located in first location of array of word table.
- this table must be compiled with absolute directive and the start address of table must be initialized in dynamic_var_addr variable.
Library here: http://www.microelemente.ro/MikroPascal ... y_V1_4.zip
Now, library can receive UDP broadcast packets and can insert dynamic string variables in HTML code.
1. UDP broadcast
- can be enabled or disabled via udp_broadcast flag.
this flag is default false and can be activated after Eth_Init routine.
Code: Select all
Eth_Init;
udp_broadcast := true;
2. Dynamic string variables in HTML code
- added a new value for Socket.RAM_ROM, this is 2.
- when Socket[j].RAM_ROM = 2, MCU will search in HTML const after "@" char. This must be followed by two numbers from 00 to 99.
- user must make a table (array[x] of word) with string variables address. When MCU will found "@00" will copy in ETH mem, the string that have start address located in first location of array of word table.
- this table must be compiled with absolute directive and the start address of table must be initialized in dynamic_var_addr variable.
Code: Select all
var dat4 : string[10];
dat5 : string[5];
dat9 : string[10];
dat10 : string[5];
my_dynamic_var : array[4] of word; absolute $100;
...
procedure Init_dynamic_var;
begin
my_dynamic_var[0] := word(@dat4);
my_dynamic_var[1] := word(@dat5);
my_dynamic_var[2] := word(@dat9);
my_dynamic_var[3] := word(@dat10);
end;
...
Eth_Init;
dynamic_var_addr := $100; // after Eth_Init...
Init_dynamic_var;
Code: Select all
procedure HTTPProcDataIn(len_ : word; j : byte);
var i : byte;
getRequest,txt31 : string[32];
begin
if len_ > 32 then len_ := 32;
CopyEthMem_CPToRam(word(@getRequest), len_);
txt31 := httpMethod;
if Mem_Cmp(word(@getRequest), word(@txt31), Str_Len(txt31)) <> 0 then exit; // only GET method is supported here
Socket[j].RAM_ROM := 2; // here ....
Socket[j].Keep_Alive := false;
Socket[j].Start_addr := @indexPage1;
Socket[j].Stop_addr := @indexPage1 + indexPage1_len;
end;
Code: Select all
'<table width="100%" cellspacing="0">'+
'<tr>'+
'<td class="gensmall">Last visit was: @00 </td>'+ // MCU will put instead of @00, string dat4
'<td class="gensmall" align="right">It is currently @01 <br /></td>'+ // MCU will put instead of @00, string dat5
'</tr>'+
'</table>';
Best regards, Florin Andrei Medrea.
http://www.microelemente.ro/
http://www.microelemente.ro/produse-si-servicii/
http://www.microelemente.ro/custom-software/
mail : florin@microelemente.ro
http://www.microelemente.ro/
http://www.microelemente.ro/produse-si-servicii/
http://www.microelemente.ro/custom-software/
mail : florin@microelemente.ro
Re: Additional library for MikroPascal PRO 2009
Thanks!
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)
-
- Posts: 272
- Joined: 17 Feb 2009 02:39
- Location: Colombia
- Contact:
Re: Additional library for MikroPascal PRO 2009
Thanks! excellent work.
-
- Posts: 47
- Joined: 24 Oct 2009 16:01
- Location: Colombia
Re: Additional library for MikroPascal PRO 2009
Good day,
the library is only for PIC18F97J60 family?
the library is only for PIC18F97J60 family?
Re: Additional library for MikroPascal PRO 2009
Hello,juanelectro wrote:the library is only for PIC18F97J60 family?
For all P18 family!
Best regards, Florin Andrei Medrea.
http://www.microelemente.ro/
http://www.microelemente.ro/produse-si-servicii/
http://www.microelemente.ro/custom-software/
mail : florin@microelemente.ro
http://www.microelemente.ro/
http://www.microelemente.ro/produse-si-servicii/
http://www.microelemente.ro/custom-software/
mail : florin@microelemente.ro
Re: Additional library for MikroPascal PRO 2009
Hello Yo2ilo, Dany says I should ask you about SDMMC_SPI2.
My code is here: http://www.mikroe.com/forum/viewtopic.p ... 53#p124253
Can you help me, whats the problem with this?
Thank you very much!
Zsola
My code is here: http://www.mikroe.com/forum/viewtopic.p ... 53#p124253
Can you help me, whats the problem with this?
Thank you very much!
Zsola
Re: Additional library for MikroPascal PRO 2009
I don't have any idea, but this is the library:Zsola wrote:Hello Yo2ilo, Dany says I should ask you about SDMMC_SPI2.
My code is here: http://www.mikroe.com/forum/viewtopic.p ... 53#p124253
Can you help me, whats the problem with this?
Code: Select all
unit SDMMC_SPI2;
function SDMMC_Init : boolean;
function SDMMC_ReadSector(Sector : dWord; var MMC_Buffer : array[512] of byte) : boolean;
function SDMMC_WriteSector(Sector : dWord; var MMC_Buffer : array[512] of byte) : boolean;
const CMD0 = $40 + 0; // GO_IDLE_STATE
CMD1 = $40 + 1; // SEND_OP_COND
CMD8 = $40 + 8; // SEND_IF_COND
CMD9 = $40 + 9; // SEND_CSD
CMD10 = $40 + 10; // SEND_CID
CMD12 = $40 + 12; // STOP_TRANSMISSION
CMD16 = $40 + 16; // SET_BLOCKLEN
CMD17 = $40 + 17; // READ_SINGLE_BLOCK
CMD18 = $40 + 18; // READ_MULTIPLE_BLOCK
CMD23 = $40 + 23; // SET_BLOCK_COUNT
CMD24 = $40 + 24; // WRITE_BLOCK
CMD25 = $40 + 25; // WRITE_MULTIPLE_BLOCK
CMD41 = $40 + 41; // SEND_OP_COND (ACMD)
CMD55 = $40 + 55; // APP_CMD
CMD58 = $40 + 58; // READ_OCR
TimeOutLimit = 10000; // Set timeout limit based on clock
sdMMC = 1; // Multi Media Card (MMC)
sdSD = 2; // Secure Digital Card (SD)
sdSDHC = 4; // High Capacity Secure Digital Card (SDHC)
var SDMMC_CS : sbit; sfr; external;
SDMMC_CS_dir : sbit; sfr; external;
cardtype : byte;
implementation
procedure SDMMC_Write(tx_data : byte);
begin
asm
MOVF SSP2BUF,W
end;
SSP2BUF := tx_data;
ClrWdt;
while SSP2STAT.BF = 0 do;
asm
MOVF SSP2BUF,W
end;
end;
procedure SDMMC_Read;
begin
asm
MOVF SSP2BUF,W
SETF SSP2BUF
end;
ClrWdt;
while SSP2STAT.BF = 0 do;
asm
MOVFF SSP2BUF,R18
end;
end;
function SeekResponse(Required : Byte) : Byte;
var Index : Word;
begin
Index := 0;
while Index < $FFFF do
begin
SDMMC_Read;
result := R18;
if result = Required then break;
inc(Index);
end;
end;
function SendCmd(Cmd : Byte; Arg : dWord) : Byte;
var CRC,index : Byte;
begin
if SeekResponse($FF) <> $FF then result := $FF // wait for ready
else
begin
SDMMC_Write(Cmd); // Command
SDMMC_Write(Highest(Arg)); // Argument[31..24]
SDMMC_Write(Higher(Arg)); // Argument[23..16]
SDMMC_Write(Hi(Arg)); // Argument[15..08]
SDMMC_Write(Lo(Arg)); // Argument[07..00]
CRC := $FF; // Default CRC byte
if Cmd = CMD0 then CRC := $95 // CRC for CMD0($0)
else if Cmd = CMD8 then CRC := $87; // CRC for CMD8($1AA)
SDMMC_Write(CRC);
Index := 0;
while Index < 100 do
begin // Receive command response
inc(index);
SDMMC_Read;
result := R18;
if (result and $80) < 2 then break; // Wait for a valid response in timeout of 100 attempts
end;
end;
end;
function SDMMC_ReadSector(Sector : dWord; var MMC_Buffer : array[512] of byte) : boolean;
var TimeOut : Byte;
Index : Word;
begin
result := false;
if cardtype = 0 then exit;
TimeOut := 0;
if (cardtype and $04) = 0 then Sector := Sector shl 9; // MMC or SD - byte addressing (SDHC use block addressing)
while result = false do
begin
SDMMC_CS := 0;
nop;
nop;
if SendCmd(CMD17, Sector) = $00 then // Send Cmd 17
if SeekResponse($FE) = $FE then // Read start token
begin
Index := 0;
FSR2 := word(@MMC_Buffer);
while Index < 512 do // Read data block
begin
SDMMC_Read;
POSTINC2 := R18;
Inc(Index);
end;
SDMMC_Read; // Read dummy CRC to conclude data block
SDMMC_Read;
result := true; // Read completed successfully
end;
SDMMC_CS := 1;
nop;
nop;
SDMMC_Read; // Clock SD/MMC to complete read
if Inc(TimeOut) > 1 then break
end;
end;
function SDMMC_WriteSector(Sector : dWord; var MMC_Buffer : array[512] of byte) : boolean;
var Response : Byte;
Index : Word;
TimeOut : Byte;
begin
result := false;
if cardtype = 0 then exit;
TimeOut := $00;
if (cardtype and $04) = 0 then Sector := Sector shl 9; // MMC or SD - byte addressing (SDHC use block addressing)
while result = false do
begin
SDMMC_CS := 0;
nop;
nop; // Send Cmd 24
if SeekResponse($FF) = $FF then // Wait for ready
if SendCmd(CMD24, Sector) = $00 then
begin
SDMMC_Write($FE); // Write start token
Index := 0;
FSR2 := word(@MMC_Buffer);
while Index < 512 do // Write data block
begin
SDMMC_Write(POSTINC2);
Inc(Index);
end;
SDMMC_Read; // Send dummy CRC to conclude data block
SDMMC_Read;
SDMMC_Read;
Response := R18; // Data response token
Response := Response and $1F;
if Response = $05 then result := true;
end;
SDMMC_CS := 1;
nop;
nop;
SDMMC_Read; // Complete SPI transaction
if Inc(TimeOut) > 10 then break;
end;
end;
function Cmd5541(BitSet : Boolean) : Byte;
begin
result := SendCmd(CMD55, 0);
if result > 1 then Exit
else
begin
if BitSet = true then result := SendCmd(CMD41, $40000000)
else result := SendCmd(CMD41, 0);
end;
end;
function SDMMC_Init_ : boolean;
var Index : Word;
OCR : array[4] of Byte;
tmp : string[2];
begin
result := true;
cardtype := 0;
SDMMC_CS := 1; // Pull CS high
SDMMC_CS_dir := 0;
Index := 0;
while Index < 20 do // Clock SD for min 80 cycles
begin
SDMMC_Read;
inc(Index);
end;
SDMMC_CS := 0; // Pull CS low
nop;
nop;
if SendCmd(CMD0, 0) = $01 then // Send Cmd 0 - enter idle state
if SendCmd(CMD8, $01AA) = $01 then // SDC Version 2+
begin
for Index := 0 To 3 do
begin
SDMMC_Read;
OCR[Index] := R18;
end;
if (OCR[2] = $01) and (OCR[3] = $AA) then // SD Vdd range of 2.7 - 3.6 volts
begin
Index := TimeOutLimit;
while Index > 0 do
begin
dec(Index);
if Cmd5541(True) = 0 then break;
end;
if Index > 0 then // Cmd 55/41 successful with HCS bit set
if SendCmd(CMD58, 0) = 0 then // Send Cmd 58
begin
for Index := 0 To 3 do
begin
SDMMC_Read;
OCR[Index] := R18;
end;
// CCS[30] bit in the OCR set
if (OCR[0] and $40) > 0 then cardtype := sdSDHC // Init successful - SDHC (3)
else cardtype := sdSD; // Init successful - SD (2)
end;
end
end
else // SD Version 1 or MMC
begin
if Cmd5541(False) <= 1 then
begin
cardtype := sdSD; // Init successful - SD (2)
Index := TimeOutLimit;
while Index > 0 do
begin
dec(Index);
if Cmd5541(True) = 0 then break;
end;
end // Wait for leaving idle state
else
begin
cardtype := sdMMC; // Init successful - MMC (1)
Index := TimeOutLimit;
while Index > 0 do
begin
dec(Index);
if SendCmd(CMD1, 0) = 0 then break; // Wait for leaving idle state
end;
end;
end;
if Index = 0 then result := false
else SendCmd(CMD16, $0200);
SDMMC_CS := 1;
nop;
nop;
SDMMC_Read; // Clock SD/MMC to complete
end;
function SDMMC_Init : boolean;
var Index : byte;
begin
Index := 0;
while Index < 10 do
begin
result := SDMMC_Init_;
if cardtype <> 0 then break;
inc(index);
end;
if cardtype <> 0 then result := true;
end;
end.
Best regards, Florin Andrei Medrea.
http://www.microelemente.ro/
http://www.microelemente.ro/produse-si-servicii/
http://www.microelemente.ro/custom-software/
mail : florin@microelemente.ro
http://www.microelemente.ro/
http://www.microelemente.ro/produse-si-servicii/
http://www.microelemente.ro/custom-software/
mail : florin@microelemente.ro
Re: Additional library for MikroPascal PRO 2009
Thank you Florin, if I figure out what was the cause, I will let you know!
Anyway, you are close enough to me (I'm near Budapest).
Be well!
Anyway, you are close enough to me (I'm near Budapest).
Be well!
Re: Additional library for MikroPascal PRO 2009
I have just figured out what was wrong!
It seems the PORT MAPPING is faulty, unless someone find difference in the uP and assembly code. Just because I not find. Someone?
The hardware config is the same, 1WayIOLOCK Set bit Disabled.
This is NOT working, the detection of the cards lasts 8-60s with 0 cardtype and any card:
Unlock_IOLOCK;
PPS_Mapping(0, _OUTPUT, _CCP1_P1A);
PPS_Mapping(1, _OUTPUT, _CCP2_P2A);
PPS_Mapping(11, _INPUT, _SDI2); //SDI2
PPS_Mapping(12, _INPUT, _SCK2IN); //SCK2IN
PPS_Mapping(17, _OUTPUT, _SDO2); //SDO2
PPS_Mapping(12, _OUTPUT, _SCK2); //SCK2
Lock_IOLOCK;
However the clock out is right, the PWM is working, and data out is OK - but no input, especially the SCLKIN i think. Just before this I disabled interrupts (maybe I should enable GIE after all?).
And this IS WORKING, the card recognition is blazingly fast (with PIC18F46J50@10MHz).
asm
movlb 0x0E //Select bank 14 for access to PPS registers
bcf INTCON, GIE //I/O Pin unlock sequence will not work if CPU services an interrupt during the sequence
movlw 0x55 //Unlock sequence consists of writing 0x55
movwf EECON2 //;and 0xAA to the EECON2 register.
movlw 0xAA
movwf EECON2
bcf PPSCON, IOLOCK // ;We may now write to RPINRx and RPORx registers
//Input SDI2, SCK2IN - RPINR21-RP11, RPINR22 /CLK:RC1(RP12), DI:RC0(RP11)
movlw 0x0B //;RP11 will be SDI2
movwf RPINR21 //;Assign the SDI2 function to pin RP11
movlw 0x0C //;SCK2 also needs to be configured as an input on the same pin
movwf RPINR22 //;SCK2 input function taken from RP12
// OUT
movlw 0x0A //;Let’s assign SCK2 output
movwf RPOR12 //;RPOR4 maps output signals to RP12
movlw 0x09 //;0x09 is SDO2 output
movwf RPOR17 //;Assign SDO2 output signal to the RP17
movlw 0x0E //PWM1
movwf RPOR0
movlw 0x12 //PWM2
movwf RPOR1
//SET IOLOCK
movlw 0x55 //Unlock sequence consists of writing 0x55
movwf EECON2 //;and 0xAA to the EECON2 register.
movlw 0xAA
movwf EECON2
bsf PPSCON, IOLOCK // ;We may now write to RPINRx and RPORx registers
bsf INTCON, GIE // ;May now turn back on interrupts if desired
movlb 0x0F //;Done with PPS registers, bank 15 has other SFRs
end;
(Don't mention about comments, Im not sure everything is correct.)
The summary of the s**king: The SD-MMC and SPI2 is not documented enough in the compilers, till now the SPI2 support and PWM2 support is missing from 18F4xJx family, I have checked in the latest beta too.
I found circuits with pullup resistors and without, the SD documentations have holes (CLK is high or low, when latch the data and is the IO lines use open collector/drain or push-pull gates!? and so on). I had to modifiy my circuit to sure SD card get 3,3V (not 3V as it got). I had to pull up all the data lines - but its good against floating.
I had to read a lot of docs, now I understand SD and MMC specs with its differences. I analyze your SD-MMC library (fine ), and of course write a lot in assembly.
Thank you much Yo2lio!
Greetings!
It seems the PORT MAPPING is faulty, unless someone find difference in the uP and assembly code. Just because I not find. Someone?
The hardware config is the same, 1WayIOLOCK Set bit Disabled.
This is NOT working, the detection of the cards lasts 8-60s with 0 cardtype and any card:
Unlock_IOLOCK;
PPS_Mapping(0, _OUTPUT, _CCP1_P1A);
PPS_Mapping(1, _OUTPUT, _CCP2_P2A);
PPS_Mapping(11, _INPUT, _SDI2); //SDI2
PPS_Mapping(12, _INPUT, _SCK2IN); //SCK2IN
PPS_Mapping(17, _OUTPUT, _SDO2); //SDO2
PPS_Mapping(12, _OUTPUT, _SCK2); //SCK2
Lock_IOLOCK;
However the clock out is right, the PWM is working, and data out is OK - but no input, especially the SCLKIN i think. Just before this I disabled interrupts (maybe I should enable GIE after all?).
And this IS WORKING, the card recognition is blazingly fast (with PIC18F46J50@10MHz).
asm
movlb 0x0E //Select bank 14 for access to PPS registers
bcf INTCON, GIE //I/O Pin unlock sequence will not work if CPU services an interrupt during the sequence
movlw 0x55 //Unlock sequence consists of writing 0x55
movwf EECON2 //;and 0xAA to the EECON2 register.
movlw 0xAA
movwf EECON2
bcf PPSCON, IOLOCK // ;We may now write to RPINRx and RPORx registers
//Input SDI2, SCK2IN - RPINR21-RP11, RPINR22 /CLK:RC1(RP12), DI:RC0(RP11)
movlw 0x0B //;RP11 will be SDI2
movwf RPINR21 //;Assign the SDI2 function to pin RP11
movlw 0x0C //;SCK2 also needs to be configured as an input on the same pin
movwf RPINR22 //;SCK2 input function taken from RP12
// OUT
movlw 0x0A //;Let’s assign SCK2 output
movwf RPOR12 //;RPOR4 maps output signals to RP12
movlw 0x09 //;0x09 is SDO2 output
movwf RPOR17 //;Assign SDO2 output signal to the RP17
movlw 0x0E //PWM1
movwf RPOR0
movlw 0x12 //PWM2
movwf RPOR1
//SET IOLOCK
movlw 0x55 //Unlock sequence consists of writing 0x55
movwf EECON2 //;and 0xAA to the EECON2 register.
movlw 0xAA
movwf EECON2
bsf PPSCON, IOLOCK // ;We may now write to RPINRx and RPORx registers
bsf INTCON, GIE // ;May now turn back on interrupts if desired
movlb 0x0F //;Done with PPS registers, bank 15 has other SFRs
end;
(Don't mention about comments, Im not sure everything is correct.)
The summary of the s**king: The SD-MMC and SPI2 is not documented enough in the compilers, till now the SPI2 support and PWM2 support is missing from 18F4xJx family, I have checked in the latest beta too.
I found circuits with pullup resistors and without, the SD documentations have holes (CLK is high or low, when latch the data and is the IO lines use open collector/drain or push-pull gates!? and so on). I had to modifiy my circuit to sure SD card get 3,3V (not 3V as it got). I had to pull up all the data lines - but its good against floating.
I had to read a lot of docs, now I understand SD and MMC specs with its differences. I analyze your SD-MMC library (fine ), and of course write a lot in assembly.
Thank you much Yo2lio!
Greetings!
-
- Posts: 47
- Joined: 24 Oct 2009 16:01
- Location: Colombia
Re: Additional library for MikroPascal PRO 2009
I need to send information by TCP from PIC to server, what is the functions sequence that I must do for reaching this objetive?
Sorry by my english
Sorry by my english
Ethernet library changes...
Hello to all,
I want to make some changes in Ethernet library, for both, embedded and ENC28J60.
Now, Open_TCP_Connection function, search for opened connection and send SYN for both connected or unconnected socket.
I want to change this, to do not send SYN if socket is already connected, just reset to 0 the Socket.Exp_Time
I will add a new Open_TCP_Connection function, Open_TCP_Connection_S, this will make TCP connection and return the number of connected socket.
In this way, you will be able to send data via TCP, from both RAM or ROM and don't wait for transmission, just check periodically if Socket.Start_addr = Socket.Stop_addr and <> 0, this mean: transmission complete.
I want to make some changes in Ethernet library, for both, embedded and ENC28J60.
Now, Open_TCP_Connection function, search for opened connection and send SYN for both connected or unconnected socket.
I want to change this, to do not send SYN if socket is already connected, just reset to 0 the Socket.Exp_Time
I will add a new Open_TCP_Connection function, Open_TCP_Connection_S, this will make TCP connection and return the number of connected socket.
In this way, you will be able to send data via TCP, from both RAM or ROM and don't wait for transmission, just check periodically if Socket.Start_addr = Socket.Stop_addr and <> 0, this mean: transmission complete.
Best regards, Florin Andrei Medrea.
http://www.microelemente.ro/
http://www.microelemente.ro/produse-si-servicii/
http://www.microelemente.ro/custom-software/
mail : florin@microelemente.ro
http://www.microelemente.ro/
http://www.microelemente.ro/produse-si-servicii/
http://www.microelemente.ro/custom-software/
mail : florin@microelemente.ro
Re: Additional library for MikroPascal PRO 2009
Hello yo2ilo,
I've installed your v1.4 library pack, but in the library manager nothing appears. I have MikroPascal PRO 2.5 (also tried on v3.8 )
(The components were succesfully extracted into the uses\p18 folder by the way)
Can you please tell me what should I do?
Thanks.
I've installed your v1.4 library pack, but in the library manager nothing appears. I have MikroPascal PRO 2.5 (also tried on v3.8 )
(The components were succesfully extracted into the uses\p18 folder by the way)
Can you please tell me what should I do?
Thanks.