Searching \ for '[PIC]:Initialization code' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: piclist.com/techref/microchip/devices.htm?key=pic
Search entire site for: 'Initialization code'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]:Initialization code'
2000\08\16@184050 by Jeff Scharpf

flavicon
face
part 1 1220 bytes content-type:text/plainI was hoping someone could just take a quick look at a small snippet of code I have and tell me if there is anything obviously wrong. What I'm doing is setting up a 16F876 with porta as input, portb as input, and portc as outputs. I have all inputs for porta and portb tied to V+. I have the portc outputs going to LEDs. All I wanted to do was run timer0 internally, use the timer0 interrupt to go out and increment a register, then display this on the portc outputs to show that the interrupt is working. I used a 256 scaler so it didn't go so fast. I know that i have some defined variables that I have not used yet.I am very new at this :( Any help is greatly appreciated.
I did read the beginners help page and was able to run simple code that read an input from port a and incremented a register, then sent it to portc leds. This worked, so I believe electricallly everything is ok.

Thanks,

Jeff Scharpf


Jeffrey Scharpf
Senior Engineering Technician
Milwaukee Electric Tool Corporation
Technical Center
Brookfield, Wisconsin, 53005
(262) 783-8681
_______________________________________________________
Are you a Techie? Get Your Free Tech Email Address Now!
Many to choose from! Visit http://www.TechEmail.com

part 2 2694 bytes content-type:text/plain; name="freq.asm"
(decoded 7bit)

;freq.asm  8/17/00, jeff scharpf
;program to read pulses into TMR1 and calculate the frequency/period

               list    p=16f876
tmr0    equ     0x01
tmr1l   equ     0x0e
tmr1h   equ     0x0f
porta   equ     0x05
portb   equ     0x06
portc   equ     0x07
trisa   equ     0x85
trisb   equ     0x86
trisc   equ     0x87
status  equ     0x03
optreg  equ     0x81
INTCON  equ     0x0b
GIE     equ     7
RBPU    equ     7
INTEDG  equ     6
rp0     equ     5
T0CS    equ     5
PSA     equ     3
T0SE    equ     4
T0IE    equ     5
T0IF    equ     2
INTE    equ     4
INTF    equ     1
tmr0cnt equ     0x20    ;number of times that tmr0 overflows
timelo  equ     0x21    ;time accumulated lo byte
timehi  equ     0x22    ;time accumulated hi byte
w       equ     0
f       equ     1


       org     0x000           ;program start
       goto    start

       org     0x004           ;interrupt routine
       goto    inter


start   bsf     status,rp0      ;set rp0 to set bank1
       movlw   0xff            ;set porta to inputs
       movwf   trisa
       movlw   0xff            ;set portb to inputs
       movwf   trisb
       movlw   0x00            ;set portc to outputs
       movwf   trisc
       clrf    portb           ;set all lines on b low
       clrf    portc           ;set all lines on c low
       bsf     optreg,RBPU     ;release port b internal pullups
       bcf     optreg,INTEDG   ;set interrup to occur on falling edge
       bcf     optreg,T0CS     ;set tmr0 to perform as timer (internal)
       bcf     optreg,T0SE     ;set tmr0 to detect rising edge (n/a when using tmr0 as timer)
       bcf     optreg,PSA      ;clear prescaler bit to use TMR0
       bsf     optreg,0        ;set  bits 0-2 to 111 to make prescaler 1:256
       bsf     optreg,1
       bsf     optreg,2
       bcf     status,rp0      ;reset rp0 to set to bank0
       bsf     INTCON,T0IE     ;enable tmr0 overflow interrupt
                               ;bsf    INTCON,INTE     ;enable RB0/INT external interrupt
                               ;bcf    INTCON,INTF     ;clear RB0/INT flag
       bcf     INTCON,T0IF     ;clear tmr0 overflow flag
       bsf     INTCON,GIE      ;enable global interrupts
       clrf    tmr0            ;clear tmr0
       movlw   0xff            ;turn all portc outputs on
       movwf   portc
       clrf    tmr0cnt         ;clear out timer overflow count register

repeat
       movf    tmr0cnt,w
       movwf   portc           ;display contents of tmr0cnt
       goto    repeat

inter
       incf    tmr0cnt,f
       bcf     INTCON,INTF     ;clear interrupt flag
       retfie

       end




part 3 129 bytes
--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.

2000\08\16@191829 by George Chatzigeorgiou

flavicon
face
First a question. I can't figure out the use of ports A and B.
I'll take a look at the code.



-----Original Message-----
From: pic microcontroller discussion list
[spam_OUTPICLISTTakeThisOuTspamMITVMA.MIT.EDU]On Behalf Of Jeff Scharpf
Sent: Thursday, August 17, 2000 1:39 AM
To: .....PICLISTKILLspamspam@spam@MITVMA.MIT.EDU
Subject: [PIC]:Initialization code


I was hoping someone could just take a quick look at a small snippet of code
I have and tell me if there is anything obviously wrong. What I'm doing is
setting up a 16F876 with porta as input, portb as input, and portc as
outputs. I have all inputs for porta and portb tied to V+. I have the portc
outputs going to LEDs. All I wanted to do was run timer0 internally, use the
timer0 interrupt to go out and increment a register, then display this on
the portc outputs to show that the interrupt is working. I used a 256 scaler
so it didn't go so fast. I know that i have some defined variables that I
have not used yet.I am very new at this :( Any help is greatly appreciated.
I did read the beginners help page and was able to run simple code that read
an input from port a and incremented a register, then sent it to portc leds.
This worked, so I believe electricallly everything is ok.

Thanks,

Jeff Scharpf


Jeffrey Scharpf
Senior Engineering Technician
Milwaukee Electric Tool Corporation
Technical Center
Brookfield, Wisconsin, 53005
(262) 783-8681
_______________________________________________________
Are you a Techie? Get Your Free Tech Email Address Now!
Many to choose from! Visit http://www.TechEmail.com

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.

2000\08\16@202757 by Barry Gershenfeld

picon face
>All I wanted to do was run timer0 internally, use the timer0 interrupt to
go out and increment a register, then display this on the portc outputs to
show that the interrupt is working. I used a 256 scaler so it didn't go so
fast.

Are all the lights on? They could still be too fast to see.  With a
4 MHz crystal it would count at 1MHz; prescaled by 256 is 3.9 KHz, and
counting to 256 the topmost light still blinks at 15 Hz.

If I know what I'm talking about--I haven't done any PIC stuff yet, just
reading.

Barry

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.

2000\08\16@222323 by Greg Maki

flavicon
face
Jeff Scharpf wrote:
{Quote hidden}

snip

{Quote hidden}

Jeff,

The only thing I see wrong is that your 'clrf portb' and 'clrf portc'
are actually clearing the trisb and trisc registers since the RP0 bit is
still set. I hope you have those port pins tied to V+ with some
resistors!

Try putting the 'bcf STATUS,RP0' command after the 'movwf trisb'
command. It should work a lot better. And you might want to #include
<P16F876.INC> instead of having to define all of those registers
yourself.

Hope this helps,

Greg Maki

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.

2000\08\17@082139 by Jeff Scharpf

flavicon
face
>
> Are all the lights on? They could still be too fast to see.  With a
> 4 MHz crystal it would count at 1MHz; prescaled by 256 is 3.9 KHz, and
> counting to 256 the topmost light still blinks at 15 Hz.
>
> If I know what I'm talking about--I haven't done any PIC stuff yet, just
> reading.
>
> Barry
>

Thanks for your help
I wasn't very clear. ports b and a aren't used yet, i just left them in there for the future. I calculated that if the timr counts at even 4 mhz, (.250 microseconds), this scaled by 256 should be about 64 microseconds. If the timer goes 256 counts I figured it would take about 16 milliseconds to overflow. At this point, I wanted use the timer0 interrupt overflow to increment a register. So if I increment this register every 16 milliseconds, i realize it will be too fast to see, but if it's an 8 bit register, i should be able to see it fill up (16 milliseconds * 256 = about 4 sec)
Does this make sense?
Thanks for all the help so far. I will try the suggestions given up to this point.

Jeff
> --
> http://www.piclist.com hint: The PICList is archived three different
> ways.  See http://www.piclist.com/#archives for details.

Jeffrey Scharpf
Senior Engineering Technician
Milwaukee Electric Tool Corporation
Technical Center
Brookfield, Wisconsin, 53005
(262) 783-8681
_______________________________________________________
Are you a Techie? Get Your Free Tech Email Address Now!
Many to choose from! Visit http://www.TechEmail.com

--
http://www.piclist.com hint: To leave the PICList
piclist-unsubscribe-requestspamKILLspammitvma.mit.edu>

2000\08\17@083657 by M. Adam Davis

flavicon
face
The only thing I noticed in my brief glance was that you didn't touch the A/D
registers associated with port A.

By default, much of port A at startup are configured as A/D.  Your code will not
do much with port a until you set the A/D registers to configure port A as all
digital (or digital where you want it...)

-Adam

Jeff Scharpf wrote:
{Quote hidden}

--
http://www.piclist.com hint: To leave the PICList
.....piclist-unsubscribe-requestKILLspamspam.....mitvma.mit.edu>

2000\08\17@151531 by Jeff Scharpf

flavicon
face
On Wed, 16 August 2000, Greg Maki wrote:

{Quote hidden}

Thanks greg that fixed it. Now I have what appears to be an MLAB problem ! :(

Jeff

Jeffrey Scharpf
Senior Engineering Technician
Milwaukee Electric Tool Corporation
Technical Center
Brookfield, Wisconsin, 53005
(262) 783-8681
_______________________________________________________
Are you a Techie? Get Your Free Tech Email Address Now!
Many to choose from! Visit http://www.TechEmail.com

--
http://www.piclist.com hint: To leave the PICList
EraseMEpiclist-unsubscribe-requestspam_OUTspamTakeThisOuTmitvma.mit.edu>

2000\08\17@154837 by Barry Gershenfeld

picon face
>> Are all the lights on? They could still be too fast to see.  With a
>> 4 MHz crystal it would count at 1MHz; prescaled by 256 is 3.9 KHz, and
>> counting to 256 the topmost light still blinks at 15 Hz.
>>
>> If I know what I'm talking about--I haven't done any PIC stuff yet, just
>> reading.

>Thanks for your help
>I wasn't very clear. ports b and a aren't used yet, i just left them in
there for the future. I calculated that if the timr counts at even 4 mhz,
(.250 microseconds), this scaled by 256 should be about 64 microseconds.

>Jeff

You're right, I didn't include the timer itself counting to 256, so
it should be slow enough.  I don't think you've mentioned what you
see, but I'll guess all the lights are off.

You said you'd tried a simple program first, that made the lights on
portc flash.  If you didn't use that code to start writing this program
then maybe you should take a copy of your code and just get it to
flash the lights first.  Then add the timer stuff back in.

Barry

--
http://www.piclist.com hint: To leave the PICList
piclist-unsubscribe-requestspamspam_OUTmitvma.mit.edu>

More... (looser matching)
- Last day of these posts
- In 2000 , 2001 only
- Today
- New search...