I would say there is some form of hardware fault.
From your code, I dont see how the relay could buzz as you only have code to turn it on if Adval is between 500 and 600. There is nothing in the code that I can se that will turn it OFF eg PortB.6 = 0.
The buzzing could be due to the PIC resetting. Connect an LED to an unused pin and light it for 1 second then turn it off in the initialisation code. If you see the LED flashing or aapparently staying on then for some reason your PIC is resetting.
From the code you have posted, the first time ADVAL is 500-600 the relay will operate and then stay that way forever.
I notice that you update the LCD inside the loop and that LCD Enable is on B5.
This pin will be going high and low as the LCD is updated.
Do you have a short between B5 and B6 ?
Keith
www.diyha.co.uk
www.kat5.tv
Bookmarks