hamid9543
Active Member
 
Offline
Posts: 124
Thank You
-Given: 80
-Receive: 7
|
 |
« on: January 25, 2006, 11:29:42 23:29 » |
|
hi to all member this program is very easy !but it not working:confused: plaese help me thanks hardware:pic16f877 pic basic pro main: portb=0 "clear portb" intcon=%10010000 "interrupt rb0" option_reg=%11000000 on interrupt goto int disable int: lcdout $fe,$c0,"yohooo!" resume enable goto main end
|
|
|
Logged
|
|
|
|
metal
Global Moderator
Hero Member
   
Offline
Posts: 2420
Thank You
-Given: 862
-Receive: 678
Top Topic Starter
|
 |
« Reply #1 on: January 26, 2006, 03:04:27 15:04 » |
|
Hi
I am glad that you have started writing your own code now, I can say I will help you this time !! As I stated earlier, I will be of great help to members who always try to help their selves first, I can see you passed this stage now 
Compile this code, connect a LED to PORTB.1, use 470 Ohm resistor, when you pull PORTB.0 to low, the LED will flicker for approximatelly 10 seconds. I have already tested this code.
Plz, read the comments carefully so you try to understand why your code didnot work, I see that you haven't setup ADCON1, and started with LCD while haven't posted how you have connected it, review the manual in order to see how its connected.Code:[SIZE=2][COLOR=Green]@ Device PIC16F877A, HS_OSC, BOD_OFF, PWRT_ON, WDT_ON, PROTECT_OFF[/COLOR] [COLOR=Navy]' Tell the compiler that you are using 20MHz crystal[/COLOR] [B]DEFINE[/B] OSC 20
[B]ON INTERRUPT GOTO[/B] INT
i [B]VAR BYTE[/B] : i = 0
[B]GoSub[/B] InitCPU
MAIN: [B]WHILE[/B] 1 [B]WEND[/B]
InitCPU:
[COLOR=Navy]' All digital I/O[/COLOR] ADCON1 = 7
[COLOR=Navy]' PORTB pull-ups are enabled ' Interrupt on falling edge of RB0/INT pin ' TMR0 Internal instruction cycle clock ' Increment on low-to-high transition on RA4/T0CKI pin ' Prescaler is assigned to the Timer0 module ' Prescaler Rate 1:2[/COLOR] OPTION_REG = %10000000
[COLOR=Navy]' GIE = 1 --> Enables all unmasked interrupts ' INTE = 1 --> Enables the RB0/INT external interrupt ' INTF = 0 --> Clear RB0/INT flag bit to avoive erronous intrrupt[/COLOR] INTCON = %10010000
[COLOR=Navy]' PORTA all outputs[/COLOR] TRISA = 0
[COLOR=Navy]' PORTB all outputs except PORTB.0[/COLOR] TRISB = %00000001
[B]RETURN[/B]
[B]DISABLE[/B] INT: [COLOR=Navy]' GIE = 0 --> Disables all unmasked interrupts[/COLOR] INTCON.7 = 0 [COLOR=Navy]' What you want to do with INT[/COLOR] [B]FOR[/B] i = 0 [B]TO[/B] 9 PORTB.1 = 1 [B]PAUSE[/B] 500 PORTB.1 = 0 [B]PAUSE[/B] 500 [B]NEXT[/B] [COLOR=Navy]' Clear RB0/INT interrupt flag bit[/COLOR] INTCON.1 = 0 [COLOR=Navy]' GIE = 1 --> Enables all unmasked interrupts[/COLOR] INTCON.7 = 1 [COLOR=Navy]' Return to main program[/COLOR] [B]RESUME[/B] [B]ENABLE[/B]
[B]END[/B][/SIZE]
|
|
« Last Edit: January 26, 2006, 04:26:45 16:26 by metal »
|
Logged
|
|
|
|
hamid9543
Active Member
 
Offline
Posts: 124
Thank You
-Given: 80
-Receive: 7
|
 |
« Reply #2 on: January 26, 2006, 10:18:17 22:18 » |
|
hi metal thanks for your help and thank for quick replay i writing code same as you. but it is no working corect: lcd show: line1)hamid line2)(when interrupt) "key= 9........" or "key=3........" sotware is pbp,proteus 6.7 hardware is pic16f877 code define osc 20 define lcd_dreg porta define lcd_dbit 0 define lcd_rsreg porta define lcd_rsbit 4 define lcd_ereg porte define lcd_ebit 2 define lcd_bits 4 define lcd_lines 2 lcdout $fe,1,"HAMID" adcon1=7 option_reg=%10000000 intcon=%10010000 trisb=%00000001 k var byte for k=0 to 9 on interrupt goto int disable int: lcdout $fe,$c0,"key=",dec k next k intcon.1=0 resume enable end
|
|
|
Logged
|
|
|
|
harri_el_sucio
Newbie
Offline
Posts: 14
Thank You
-Given: 4
-Receive: 6
|
 |
« Reply #3 on: January 27, 2006, 05:05:33 17:05 » |
|
Hello METAL: Thanks Metal for their explanation to are good and to be thankful as it helps to all . Tt asks: Enable and Disable you would to be within routine INT? Sorry by my bad language Thanks
|
|
|
Logged
|
|
|
|
metal
Global Moderator
Hero Member
   
Offline
Posts: 2420
Thank You
-Given: 862
-Receive: 678
Top Topic Starter
|
 |
« Reply #4 on: January 27, 2006, 05:40:06 17:40 » |
|
Hi
enable & disable are used to diable interrupt check routines that are added by PICBasic pro, the way I plced them is correct.
|
|
|
Logged
|
|
|
|
picstudent
Active Member
 
Offline
Posts: 169
Thank You
-Given: 0
-Receive: 3
|
 |
« Reply #5 on: January 29, 2006, 03:04:14 03:04 » |
|
so you are workin on proton+ or ...
|
|
|
Logged
|
... rego ... who are are you really ?
|
|
|
hamid9543
Active Member
 
Offline
Posts: 124
Thank You
-Given: 80
-Receive: 7
|
 |
« Reply #6 on: January 29, 2006, 02:15:12 14:15 » |
|
hi i write code in pic basic pro thanks
|
|
|
Logged
|
|
|
|
tasosstr
Junior Member

Offline
Posts: 75
Thank You
-Given: 95
-Receive: 14
|
 |
« Reply #7 on: January 29, 2006, 02:37:19 14:37 » |
|
Hello try this :
define osc 20 define lcd_dreg porta define lcd_dbit 0 define lcd_rsreg porta define lcd_rsbit 4 define lcd_ereg porte define lcd_ebit 2 define lcd_bits 4 define lcd_lines 2
adcon1=7 option_reg=%10000000 intcon=%10010000 trisb=%00000001
k var byte
lcdout $fe,1,"HAMID"
for k=0 to 9 on interrupt goto int pause 100 next k
disable 'Here start the interrupt modula ... int: lcdout $fe,$c0,"key=",dec k intcon.1=0 resume enable end
Best Regards, Tasosstr
|
|
|
Logged
|
|
|
|
|