Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

what am I doin' wrong?

Status
Not open for further replies.
Well I finally got it doing what I want ,only problem is the only way to trigger it is by cycling MCLR. I know that's not the right way to do it, but everything I've tried doesn't work.
I stripped out all the non working code and this is what's left.
Any suggestions on how to trigger this with a port input (aka the correct way)



Code:
    program Chimes

sub procedure Tone1
  Sound_Play(230, 5200)
end sub
sub procedure Melody
  Tone1
end sub

main:

  TRISB = 0

  Sound_Init(PORTB,2)   ' Initialize sound engine

    Melody                ' Play the chimes
    DELAY_MS(25000)           'DELAY FOR 25 SECONDS
    DELAY_MS(25000)           '  DELAY FOR 25 SECONDS
     DELAY_MS(25000)           ' DELAY FOR 25 SECONDS
      DELAY_MS(25000)           ' DELAY FOR 25 SECONDS

 end.
 
Did you try AtomSoft's code posted 5 posts above? If so, what did it do?

Mike.
 
What happens if you change it to,
Code:
program Chimes

sub procedure Tone1
  Sound_Play(130, 6200)     ' The 6200 controls the tone length
end sub

sub procedure Melody
  Tone1
end sub


main:
  TRISA = 0xFF

  Sound_Init(PORTB,2)   ' Initialize sound engine

e_loop:
  IF PORTA.0 = [COLOR="Blue"]1[/COLOR] THEN        '   if input at porta.0 goes low
    Melody                   ' Play the chimes
    DELAY_MS(2000)           'This just delays 2 seconds not play
  END IF

   goto e_loop
end.

Mike.
 
This makes no sense. Could it be something silly like the IDE is compiling the file that is on disk and you need to save your file prior to compiling? Can you single step through the code to see what it is doing?

Mike.
 
I'll have to look up stepping through the code. As far as saving, I've been working on this
off and on all day and it's been saved several times . I even tried a different pic in case I somehow toasted this one. At one point I added the code to turn on a led (different output from sound) if button pressed,and that didn't work.
 
I would suggest putting the button back into things, and make sure you add a debounce in your code by means of Delay(MS). Also Why not use the External Interrupt or On-Change feature here. FYI: I use ME's EasyPIC5 board and their Pascal compiler.

-BaC
PS. a 12F683 Would be perfect here!

Can't do a step through..this pic 16F628 ,not supported.If it wasn't for bad luck.....
 
Last edited:
try to use RA2 this time and set to pullup and give a try
Code:
program Chimes

sub procedure Tone1
  Sound_Play(130, 6200)     ' The 6200 controls the tone length
end sub

sub procedure Melody
  Tone1
end sub


main:
  TRISA = 0xFF

  Sound_Init(PORTB,2)   ' Initialize sound engine

e_loop:
  IF PORTA.2 = 0 THEN        '   if input at porta.0 goes low
    Melody                   ' Play the chimes
    DELAY_MS(2000)           'This just delays 2 seconds not play
  END IF

   goto e_loop
end.
 
Last edited:
Your on a mission now aren't you? Haha I would be doing the same, saying damn this should be working!

-BaC
try to use RA2 this time and set to pullup and give a try
Code:
program Chimes

sub procedure Tone1
  Sound_Play(130, 6200)     ' The 6200 controls the tone length
end sub

sub procedure Melody
  Tone1
end sub


main:
  TRISA = 0xFF

  Sound_Init(PORTB,2)   ' Initialize sound engine

e_loop:
  IF PORTA.2 = 0 THEN        '   if input at porta.0 goes low
    Melody                   ' Play the chimes
    DELAY_MS(2000)           'This just delays 2 seconds not play
  END IF

   goto e_loop
end.
 
That didn't work either,nothing happens. Had JP21 set to pullup and switch 1 set to on,and JP17set to ground.
Apparently I'm having trouble with inputs. I put this code together to see what would happen
and of course nothing did. For this I changed to pulldown and vcc on JP17.
Did I leave anything out?

: Also noted that I couldn't find any MikroE examples that had a pushbutton input. Almost all the examples are a sort of free running oscillator in that they start running as soon as programmed.


Code:
  program input_test '16F628   8mhz
porta.0 = 1         'porta.0 as input
portb.0 = 0         ' portb.0 as output

if porta.0 = 1 then    'if button porta.0 pressed
portb.0 = 1            ' then led portb.0 turns on
end if

end.
 
Try putting CMCON = 7 or CMCON = %111 in the initialization portion of your code.

-BaC
 
Last edited:
Here it is. I may need a lot more to make it work, but I don't know what it would be.
Using HS enabled and WDT, LVP , XINT disabled.

Code:
    program input_test '16F628   8mhz
porta.0 = 1         'porta.0 as input
portb.0 = 0         ' portb.0 as output
CMCON = 7
if porta.0 = 1 then    'if button porta.0 pressed
portb.0 = 1            ' then led portb.0 turns on
end if

end.
 
Let me find specifics for the PIC, I am not sure if I can test it with my EasyPIC5 board, since I don't have any in stock. But I can tell you that code will not work. You must initialize various things, such as TRISA = %00000001, to set porta.0 to input. Again let me look=up somethings and I will post a sample code. I downloaded the trial of ME Basic so I can really test it;)

-BaC
Here it is. I may need a lot more to make it work, but I don't know what it would be.
Using HS enabled and WDT, LVP , XINT disabled.

Code:
    program input_test '16F628   8mhz
porta.0 = 1         'porta.0 as input
portb.0 = 0         ' portb.0 as output
CMCON = 7
if porta.0 = 1 then    'if button porta.0 pressed
portb.0 = 1            ' then led portb.0 turns on
end if

end.
 
I really appreciate all the help. I know it's hard troubleshooting with someone on the other end that doesn't know which end is up. Added the other line like you said , it made no difference. Did I put it in the right place?

#program input_test '16F628 8mhz
trisa = %00000001
porta.0 = 1 'porta.0 as input
portb.0 = 0 ' portb.0 as output
CMCON = 7
if porta.0 = 1 then 'if button porta.0 pressed
portb.0 = 1 ' then led portb.0 turns on
end if

end.
 
How about you set the button to portA.0, pull-down enabled for port A.0 (EP3 Board DIP Switch), button set to VCC (Jumper EP3 board?).

The only significant code is the Interrupt, which will happen for each button press. We are going to need debounce for the mechanical contacts from the button. But that is more trial and error based.

let me know,
-BaC

Code:
program test
sub procedure interrupt
   If INTCON.INTF = 1 Then    ' Must read status once in order to set to 0
   PortA.0 = 1   	            ' LED PortA.0 High
   End If
   INTCON.INTF = 0          
end sub

sub procedure INIT_Reg
   OPTION_REG = 0
   INTCON = 0
   OPTION_REG.INTEDG = 1    ' interrupt on RB0 rising edge
   INTCON.INTE = 1        
   INTCON.INTF = 0        
   INTCON.GIE = 1                ' enable global interrupts
end sub

main:
   PORTA = %00000000
   PORTB = %00000000	    'All ports set to Low, 0 Again MSBF PortB/A   76543210
			               '  				             PORTB/A %00000000
   TRISA = %00000000	   	
   TRISB = %00000001         ' RB0 as input remember MSBF So PortB/A     7654321
			               ' 			                     TRISB/A %0000001 
   INIT_Reg                ' Set things up
  While true		   ' Endless Loop
  nop 			   ' Do nothing
   Wend
end.
 
Last edited:
Status
Not open for further replies.

Latest threads

Back
Top