none
Micro controller (IC) Programming RRS feed

  • Question

  • Any one can help program a 20 pin micro controller AT89C2051 ?

    my code :

    $regfile = "89c2051.dat" ' the micro controller’s include file $crystal = 6000000 ' 6 mhz crystal used ' define variables below Dim J As Byte Dim Irrecd As Bit , I As Byte Dim K As Byte Dim L As Bit Declare Sub Fn38k6(period As Byte) Dim Period As Word Irrecd = 0 ' another name for port p1.0 Irport Alias P1.0 ' make all ports 0 P1 = 0 P3 = 255 ' make port-3 high for interrupt to work ' on interrupt - call int0_int fuction On Int0 Int0_int Set Tcon.0 ' int enabled Enable Interrupts Beg1: ' show standby mode on port-1 (yellow led on) P1.1 = 1 ' enable the int0 to work now Enable Int0 Call Fn38k6 100 ' call the subroutine to send out a beam ' of IR at 38khz freq ' int would have taken place if ir recd Disable Int0 ' disable the int now ' check if int occured If Irrecd = 0 Then ' no int occured ' so go back to standby mode P1.1 = 0 ' flash standby led Waitms 100 ' wait for ( 1/10th of a second) Goto Beg1 End If ' here int recd ' wait for about 5 secs to get into alert mode ' ir beam should be reflected for this period of 5 secs Irrecd = 0 P1.2 = 1 ' alert led on now ' below for loop will work for approx 5 seconds For J = 1 To 30  Irrecd = 0  Enable Int0  Call Fn38k6 100 ' call the subroutine to send out a beam of IR at 38khz freq ' int would have taken place if ir recd  Disable Int0 ' check if int occured If Irrecd = 0 Then ' no int occured ' so out of loop - reflective object gone  Goto Nothing End If  Waitms 100 Next J ' here ir has been recd for 5 secs ' so turn on flush for 10 seconds ' After Object Has Moved Away ' wait for obect to move away ' below for loop will work for approx 5 minutes P1.3 = 1 For I = 1 To 35 ' active led on  For J = 1 To 60  Irrecd = 0  Enable Int0  Call Fn38k6 100 ' call the subroutine to send out a beam of IR at 38khz freq ' int would have taken place if ir recd  Disable Int0 ' check if int occured If Irrecd = 0 Then ' no int occured ' so out of loop - reflective object gone  Exit For ' get out of the FOR loop End If Waitms 100 Next J Next I ' time period over so flush ' or object has moved away within 5 minutes P1.4 = 1 ' flush led and buzzer on for 10 seconds Wait 5 Wait 5 P1 = 0 ' all leds off ' get back to start Waitms 100 Goto Beg1 Nothing: ' no ir recd during the 5 min alert period ' so object has moved away ' go back to start P1 = 0 Waitms 100 Goto Beg1 ' =-=-=-=-subroutines below =-=-=-=-=-=-= Sub Fn38k6(period As Word) ' parameter 1000 = 1 second approx ' function to oscillate a port pin at 38,000 times a sec Dim Ii As Byte , Jj As Byte , Kk As Byte Dim Periods As Word Periods = Period / 100 Ii = 0 While Ii < Periods Incr Ii Jj = 0 While Jj < 5 Incr Jj Kk = 0 While Kk < 255 Incr Kk Irport = 1 NOP Irport = 0 NOP NOP Wend Wend Wend End Sub ' The Interrupt Handler For The Int0 Interrupt Int0_int: ' program comes here if int0 occurs Irrecd = 1 ' just set a flag and get back ' let the main program handle the flag condition Return

    Saturday, April 6, 2013 7:02 PM

All replies

  • This forum Is for VBA, the macro language that comes with all Office applications. Looks like you have a basic language of some form, but for us to help you really need to format the code so its readable. You also need to say what your problem is and what you want to have happen. As none of us a re likely to have your micros controller, any code we may provide will of course be untested!!

    Rod Gill

    The one and only Project VBA Book

    Rod Gill Project Management

    Sunday, April 7, 2013 2:21 AM