![]() |
![]() |
![]() |
|
|
|||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
|
|
Thread Tools | Display Modes |
|
|
(permalink) |
|
Hi ,
Im doing a project using PIC16877A,and im having problems with displaying data on seven segments display. The interrupt is not working either.I have three push buttons,one for the interrupt,one as an enter key to validate entered data,and the last to increment data(push button3).Im dispalying the channel from with the analog value is coming from and the max & min preset value for relative soil moisture(0-99).The program is supposed to work like this: (i) program runs normally ,i.e,the analog value is being read and compared frequently until the int pin is high,i.e,the push button is bieng pressed,then (ii) program is transfered to int service routine where ,it allow the user to select the channel,presently only one channel is used but more will be used.So,the channel number should be displayed and when user press the increment key,push button3, the channel number should be incremented and displayed.Same for the maximum and minimum preset value (iii)then program should return to main after each entered data has been validated using the 'enter' key and continue with the new preset min&max value Here is the code.whats going wrong?please help.Note the main program is ok,only the interrupt and displaying data which is causing problems '************************************************* ************************************************** *********** '* This program is intended for microcontroller PIC16F877A * '* The microcontroller will read voltages coming from a soil moisture sensor on its analog channel 1* '* and compare them with minimum and maximum values. If an analog input is less than the minimum preset value * '* the microprocessor will output a '1' on a respective pin of portD,and it will remain '1' until the analog * '* input exceeds the maximum preset value.These low and high logic will be used to stop and start irrigation * '* respectively. * '* * '* External Interrupt INT is used to set the maximum and minimum preset values,else default values already stored in rom is used* * '* 3 Multiplexed seven segment displays are used to display the channel(provision to add more channels in the future) and relative moisture level(0% to 99%). * '* ************************************************** ************************************************** ******** program Auto_irrigation dim actual_moist1 as word dim maxmoisture as word ' register to store maximum moisture setting dim minmoisture as word 'register to store minimum moisture setting dim b as byte dim m as byte ' m points to maxmimum and minimum values of moisture level as percentage(0-99) dim channel as byte dim data0,data1,data2 as byte dim count as word '************************************************* ****************************** sub function mask(dim num as byte) as byte ' this function returns mask ' of parameter 'num' select case num ' for common cathode 7-seg. display case 0 result = $3F case 1 result = $06 case 2 result = $5B case 3 result = $4F case 4 result = $66 case 5 result = $6D case 6 result = $7D case 7 result = $07 case 8 result = $7F case 9 result = $6F end select'case end end sub '************************************************* ***************************** sub function mask1(dim dig as byte) as byte ' this function returns mask ' of parameter 'num' select case dig ' for common cathode 7-seg. display case 0 result = $3F case 1 result = $06 case 2 result = $5B case 3 result = $4F case 4 result = $66 case 5 result = $6D case 6 result = $7D case 7 result = $07 case 8 result = $7F case 9 result = $6F end select'case end end sub '************************************************* ***************************** sub procedure prepare_digit 'this routine prepares digit to be displayed data0=mask(channel) b=m mod 10 'prepares ones digit data1=mask(b) b= (m div 10)mod 10 'prepares tens data2=mask(b) end sub '************************************************* ***************************** sub procedure prepare_digit1 'this routine prepares digit to be displayed data0=mask1(channel) b=m mod 10 'prepares ones digit data1=mask1(b) b= (m div 10)mod 10 'prepares tens data2=mask1(b) end sub '************************************************* **************************** sub procedure display 'this routine displays digits PORTC= data0 PORTB=%00010000 PORTC=data1 ' data0 is the channel number PORTB=%00100000 ' data1 and data2 forms the two digit number PORTC=data2 'representing moisture level(0-99) PORTB=%01000000 'data1 is the ones and data2 the tens PORTB=0 end sub '************************************************* ****************************** sub procedure intermede 'this sub provides a delay and displays the count=$32 'symbol -- on the moisture level display while count<>0 data1=$40 'mask for symbol - data2=$40 'mask for symbol - display dec(count) wend end sub '************************************************* ****************************** sub procedure select_channel 'this sub allow the user to choose channel while PORTB.1 <> 1 if PORTB.2 <>1 then data1= $39 ' mask for letter C ''' to display SC(Select Channel) data2= $6D 'mask for for letter S ''' display end if if PORTB.2=1 then inc(channel) if channel<=7 then data0=mask(channel) data1= $39 data2= $6D display else channel=0 data0=mask(channel) data1= $39 data2= $6D display end if end if wend intermede end sub '************************************************* ************************************ sub procedure MINMAX 'MINMAX allows the user to set the min and max while PORTB.1 <> 1 'moisture level for the selected channel if PORTB.2<>1 then 'Maximum moisture level is set first then min prepare_digit display end if if PORTB.2=1 then inc(m) if m<=99 then prepare_digit display else m=0 prepare_digit display end if end if wend maxmoisture=(m*31) div 3 intermede while PORTB.1 <> 1 if PORTB.2<>1 then prepare_digit display end if if PORTB.2=1 then inc(m) if m<=99 then prepare_digit display else m=0 prepare_digit display end if end if wend minmoisture=(m*31) div 3 intermede end sub '************************************************* ****************************** sub procedure settings while PORTB.1<>1 select_channel MINMAX wend end sub '************************************************* ****************************** '************************************************* ****************************** sub function minmoist(dim i as byte) as word 'funtion which returns the default value of minimum moisture if minmoisture=0 then 'level for each channel if no value has been stored. result=613 'the default minimum moisture level is 60% end if end sub '************************************************* ****************************** '************************************************* ******************************* sub function maxmoist(dim j as byte) as word 'function which returns the default value of maximum moisture if maxmoisture=0 then 'level for each channel if no value has been stored result=972 'the default maximum moisture level is 95% end if end sub '************************************************* ***************************** sub procedure channel_read actual_moist1= ADc_read(1) 'Reading analog input if actual_moist1>maxmoist(1) then PORTD.0=0 end if if actual_moist1<minmoist(1) then PORTD.0=1 end if end sub '************************************************* **************************** sub procedure interrupt settings intcon=$90 PORTC=0 end sub main: 'main program nop TRISA=$FF ' PortA configured as input TRISB=$07 'Pins RB0-RB3 configured as input and RB4-RB7 as output TRISC=0 'PORT C configured as output TRISD=0 'PORt D configured as output ADCON1=$80 'PortA configured as analog input intcon=$90 ' Global interrupt and INT enabled,and all other interrupts disabled while true channel_read wend end.
__________________
Have a nice day.Be happy!! $ViNkE |
|
|
|
|
|
|
(permalink) |
|
hi,
Post the program as a *.asm file or 'select' the program text in the post and use the menu bar '#' and place code quotes around the text. In that way we can simply paste into our test assemblers, OK
__________________
Eric "Good enough is Perfect" PIC tutorials: Gramo's: www.digital-diy.net/ Bill's: www.blueroomelectronics.com/ |
|
|
|
|
|
|
(permalink) | |
|
Quote:
__________________
Have a nice day.Be happy!! $ViNkE |
||
|
|
|
|
|
(permalink) |
|
Multiple routines like above can be easily "debugged" with a UART output indicating the PIC's current position/readings/registers at certain points throughout the program.
UART is very easy to learn with higher languages, such as PICbasic, and if you have a computer with Hyperterminal and a COM port, then your 50% of the way there... Use the "#" button in the text editor next time to "code" wrap your program, that way all of the tabbed lines/extra spaces will not be removed
__________________
Spency. PIC Micro's - Your mind is the limit PIC's and interfacing with other devices - a PIC Basic Guide @ digital-diy.net |
|
|
|
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|
|
|
||||
| Thread | Thread Starter | Forum | Replies | Latest |
| Program not working (16F74) | imhereithink | Micro Controllers | 4 | 1st August 2007 12:37 PM |
| faulty digital components testing,checking | walters | General Electronics Chat | 5 | 22nd August 2005 07:10 PM |
| little help with my program please - simple count loop | kud0s | Micro Controllers | 5 | 7th July 2005 09:40 PM |
| PLS HELP!!!! Need working program asap..thank you!! | silverferro | Micro Controllers | 7 | 22nd July 2004 08:46 AM |
| PicBasic Keypad program | Sora | Micro Controllers | 0 | 20th April 2004 07:01 PM |