Please teach me Programming with Bascom AVR

How to control LED with microcontroller 8535 communication TCP/IP Starter kit NM7010A..?

I have a microcontroller ATMega8535 with avr low cost micro system, avr low cost micro system have 4 port A,B,C,D port to I / O microcontoller atmega8535

 

'-------------------------------------------------------------------------------

'                       NM7010A Network Module Test
'-------------------------------------------------------------------------------
$regfile = "m8535.dat"                                      ' specify the used micro
'$programmer = 1
$prog , &HA4 , &HD9,
$crystal = 8000000                                          ' used crystal frequency
$baud = 19200                                               ' use baud rate
$hwstack = 32                                               ' default use 32 for the hardware stack
$swstack = 10                                               ' default use 10 for the SW stack
$framesize = 40                                             ' default use 40 for the frame space
 
'used constants
Const Sock_stream = $01                                     ' Tcp
'Const Sock_dgram = $02                                      ' Udp
'Const Sock_ipl_raw = $03                                    ' Ip Layer Raw Sock
'Const Sock_macl_raw = $04                                   ' Mac Layer Raw Sock
'Const Sel_control = 0                                       ' Confirm Socket Status
'Const Sel_send = 1                                          ' Confirm Tx Free Buffer Size
Const Sel_recv = 2                                          ' Confirm Rx Data Size
 
'socket status
Const Sock_closed = $00                                     ' Status Of Connection Closed
'Const Sock_arp = $01                                        ' Status Of Arp
'Const Sock_listen = $02                                     ' Status Of Waiting For Tcp Connection Setup
'Const Sock_synsent = $03                                    ' Status Of Setting Up Tcp Connection
'Const Sock_synsent_ack = $04                                ' Status Of Setting Up Tcp Connection
'Const Sock_synrecv = $05                                    ' Status Of Setting Up Tcp Connection
Const Sock_established = $06                                ' Status Of Tcp Connection Established
Const Sock_close_wait = $07                                 ' Status Of Closing Tcp Connection
'Const Sock_last_ack = $08                                   ' Status Of Closing Tcp Connection
'Const Sock_fin_wait1 = $09                                  ' Status Of Closing Tcp Connection
'Const Sock_fin_wait2 = $0a                                  ' Status Of Closing Tcp Connection
'Const Sock_closing = $0b                                    ' Status Of Closing Tcp Connection
'Const Sock_time_wait = $0c                                  ' Status Of Closing Tcp Connection
'Const Sock_reset = $0d                                      ' Status Of Closing Tcp Connection
'Const Sock_init = $0e                                       ' Status Of Socket Initialization
'Const Sock_udp = $0f                                        ' Status Of Udp
'Const Sock_raw = $10                                        ' Status of IP RAW
 
Config Pind.4 = Output                                      ' Hardware reset NM7010A module
Set Portd.4
Reset Portd.4
Waitms 12
Set Portd.4
 
Enable Interrupts
' Change the MAC & IP address, SubMask, Gateway to appropriate to your network setting
' From computer connected to the network, type //192.168.1.8/index.htm at the Internet Explorer window
Config Tcpip = Int0 , Mac = 12.128.12.34.56.78 , Ip = 192.168.1.8 , Submask = 255.255.255.0 , Gateway = 0.0.0.0 , Localport = 1000 , Tx = $55 , Rx = $55 , Twi = &HCC , Clock = 300000
 
'dim used variables
Dim S As String * 200 , Shtml As String * 15 , Sheader As String * 30
Dim Tempw As Word
Dim I As Byte , P1 As Byte , P2 As Byte
 
Do
   Tempw = Socketstat(0 , 0)                                ' get status
   If Tempw = Sock_established Then
      Tempw = Socketstat(0 , Sel_recv)                      ' get received bytes
      If Tempw > 0 Then                                     ' if there is something received
         Do
            Tempw = Tcpread(0 , S)                          ' read a line
            If Left(s , 3) = "GET" Then
               Gosub Page
            End If
         Loop Until S = ""                                  ' wait until we get an empty line
         Tempw = Tcpwrite(0 , "HTTP/1.0 200 OK{013}{010}")  ' send ok
         Gosub Stuur                                        ' GET or HEAD or POST feedback so send it
         Closesocket 0                                      ' close the connection
      End If
   Elseif Tempw = Sock_close_wait Then
      Closesocket 0                                         ' we need to close
   Elseif Tempw = Sock_closed Then
      I = Getsocket(0 , Sock_stream , 80 , 0)               ' get a new socket
      Socketlisten 0                                        ' listen
   End If
Loop
End
 
'get html page out of data
Page:
   P1 = Instr(s , " ")                                      ' find first space
   P1 = P1 + 1                                              ' 4
   P2 = Instr(p1 , S , " ")                                 ' find second space
   P2 = P2 - P1
   Shtml = Mid(s , P1 , P2)                                 ' dont use too long page names
   Shtml = Lcase(shtml)                                     ' make lower case
Return
 
'send data
Stuur:
   Dim Wsize As Word , Ihitcounter As Integer
   Tempw = Tcpwrite(0 , "Content-Type: text/html{013}{010}")
   If Shtml = "/index.htm" Then                             ' data from eeprom
      S = "<html><head><title>Innovative Electronics</title></head><body><p><b>NM7010A test<br></b>by IE team<br><br>Hits : " + Str(ihitcounter) + "</p></body></html>"
      Incr Ihitcounter                                      ' increase hitcounter
      Wsize = Len(s)                                        ' size of body
      Sheader = "Content-Length: " + Str(wsize) + "{013}{010}"
      Tempw = Tcpwritestr(0 , Sheader , 255)                ' add additional CR and LF
      Tempw = Tcpwrite(0 , S , Wsize)                       ' send body
   End If
   Shtml = ""
Return

 

Dedy_hidayat's picture

My avr low cost micro system

GroG's picture

I don't do AVR programming so

I don't do AVR programming so I'm probably not the best source.  Sadly, it looks like Visual Basic - which I don't do either.

Anyway, glancing at it I'm guessin you want to control an LED through a web browser.  To get you started so you can see basic cause and effect I would suggest modifying the following piece of code.

 

'send data
Stuur:
   Dim Wsize As Word , Ihitcounter As Integer
   Tempw = Tcpwrite(0 , "Content-Type: text/html{013}{010}")
   If Shtml = "/index.htm" Then                             ' data from eeprom
      S = "<html><head><title>Innovative Electronics</title></head><body><p><b>NM7010A test<br></b>by IE team<br><br>Hits : " + Str(ihitcounter) + "</p></body></html>"
      Incr Ihitcounter                                      ' increase hitcounter
      Wsize = Len(s)                                        ' size of body
      Sheader = "Content-Length: " + Str(wsize) + "{013}{010}"
      Tempw = Tcpwritestr(0 , Sheader , 255)                ' add additional CR and LF
      Tempw = Tcpwrite(0 , S , Wsize)                       ' send body
   End If
   Shtml = ""
Return
 
change to 
 
 
'send data
Stuur:
    if  ihitcounter Mod 2 = 0 then
            'command LED ON
     else
           'command LED OFF
    end if     
   Dim Wsize As Word , Ihitcounter As Integer
   Tempw = Tcpwrite(0 , "Content-Type: text/html{013}{010}")
   If Shtml = "/index.htm" Then                             ' data from eeprom
      S = "<html><head><title>Innovative Electronics</title></head><body><p><b>NM7010A test<br></b>by IE team<br><br>Hits : " + Str(ihitcounter) + "</p></body></html>"
      Incr Ihitcounter                                      ' increase hitcounter
      Wsize = Len(s)                                        ' size of body
      Sheader = "Content-Length: " + Str(wsize) + "{013}{010}"
      Tempw = Tcpwritestr(0 , Sheader , 255)                ' add additional CR and LF
      Tempw = Tcpwrite(0 , S , Wsize)                       ' send body
   End If
   Shtml = ""
Return

 

I don't  know the command to turn on or off an LED for this system but you should just need to put it where I put the comments - what will happen is the LED should turn off and on each time you refresh the browser.