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.

More questions, datasheet, i/o, digital

Status
Not open for further replies.

bergaliv

New Member
Hello again good people.

Man, pic's are overwhelming:) Information is scattered all over the internet, bits and peices everywhere. The problem is to get a grasp of it all, when you don't know the terminology. As a newcommer to pic programming, it seems impossible to get a complete picture on what does what.
I'll try to ask questions in a way that will help me find solutions on my own. I still need some pointers to show me if I'm heading in the right direction, or if I have completely missunderstood it all(most likely:))

So, on with the questions.
1: Input/Output ports.
TRISA.0 = 1 <-- would this make PORTA.0 input? and the logically;
TRISA.6 = 1 would be input?(and so on)

2: adcon1 digital
Here's a bit I have some problems understanding. In the datasheet for 18f1320, i find a table(10:2). It shows 7 configurable bits(?) and a -(which i'm guessing means that it's not used).
Does this translate to the following?;
ADCON1 = 0000001 ; all analoge, except PORTA.0 ? (note that it's only 7 "bits". Or should it be;
ADCON1 = 00000001; 8(bits) PORTA.0 digital?

I'm trying to make sence out of the datasheet, so if(again, most likely) i have missunderstood it all, i'd very much appreciate if someone would take the time to explain this relationship datasheet-->program to me.

And last;

If someone could show a very simple program that let's me use the pickit2 logic analyzer to show the status of a led(just one led, as simple as possible) i'd be very greatful. I have tried, and failed, over and over(and crasched pickit2 software so bad that it lost it's operating system...lol)

Thanks in advance

Bergaliv

<edit>Program examples in swordfish basic please:))</edit>
 
Last edited:
Hello again good people.


1: Input/Output ports.
TRISA.0 = 1 <-- would this make PORTA.0 input? and the logically;
TRISA.6 = 1 would be input?(and so on)
Yes, the easy way to remember is to spell the word input with a one, ie: 1nput and 0utput with a zero.

2: adcon1 digital
Here's a bit I have some problems understanding. In the datasheet for 18f1320, i find a table(10:2). It shows 7 configurable bits(?) and a -(which i'm guessing means that it's not used).
Does this translate to the following?;
ADCON1 = 0000001 ; all analoge, except PORTA.0 ? (note that it's only 7 "bits".
Yes
Or should it be;
ADCON1 = 00000001; 8(bits) PORTA.0 digital?
No

Look at RA5 on the 18F1320, its digital [Input Only], MCLR or Vpp

And last;

If someone could show a very simple program that let's me use the pickit2 logic analyzer to show the status of a led(just one led, as simple as possible) i'd be very greatful. I have tried, and failed, over and over(and crasched pickit2 software so bad that it lost it's operating system...lol)

Thanks in advance

Bergaliv

<edit>Program examples in swordfish basic please:))</edit>

Hi,
Cant help you with Swordfish.

Look at 'Gramo's link near my signature for SW info.:)
 
Last edited:
I've read that link over and over:) I must have read 90% of all pic related tutorials online.

Still,, could someone tell me if my above examples are correct?
 
I've read that link over and over:) I must have read 90% of all pic related tutorials online.

Still,, could someone tell me if my above examples are correct?

I have already helped about your examples, read the blue text....:)
 
Yes, that's where I bought the kit i'm using(junebug).

I've allways been interested in the embedded thing, but it took a long time before I actually took the jump to test it.

Day one i allmost regretted it:)

Now, it seems like i'm slowly getting to understand the basics. But, looking forward, it's seems almost impossible to get further then the 100 different ways to blink a led i've done so far..heh

Kidding aside, the junebug kit(i've had it a couple of days now) seems to be perfect to start out on. There are many different ways to experiment, and combine the different things on there. Slowly, but steady it teaches the how things interact, and the led output is a beautiful way to make sure it works as expected.

I'm very greatful for the help i've been given here so far, and I'm sure that i'll ask about other things as well. Sometimes it's just frustrating to search the net for hours without finding what you are looking for. That's when the forums come in, as a last resort(to not exhaust everyone with questions as soon as a problem occures).

Give me a week or so, and I'll write my experience with the junebug up in a pdf document, in a sort of "this is how I got started with the junebug" way.
 
hi,

Actually theres a 1001 ways to blink an LED...:rolleyes:

I know what you mean about the PIC data, there is so much data and detail to read thru, if you tried to read and understand all of it before you started to 'play' with the device, it would be obsolete.!

Hands on trial and error will teach you, just be aware of the limitations of the PIC's power ratings for supplies, inputs and outputs, so that you dont blow it up while experimenting.
Other than that they are quite robust devices.

Happy programming.:)

EDIT: I'm sure Bill would like to see that pdf.
Give me a week or so, and I'll write my experience with the junebug up in a pdf document, in a sort of "this is how I got started with the junebug" way.
 
Last edited:
I've been following the thread but haven't had time to put any creative input in. I'd be very interested in your PDF and perhaps we can turn your struggles into a JPUG article that can help people starting out on PICs.

The debugger is an awesome tool as it lets you see the inner workings of an actual PIC. The best examples are often in assembly as it's a 1:1 ratio (1 line code = 1 instruction)

The Inchworm quick project PDF on my site has a introduction to MPLAB and it can easily be adapted to the Junebug & 18F1320 tutor.

I also advocate the use of Swordfish BASIC for beginners (not an opinion shared by everyone :) on the forums) as a quick start much like the BASIC Stamp or PICAxe is (although Swordfish being a true compiler will outperform either of those) and it's a really well written compiler and IDE.

C18 (C is the tool the pros use) I'm a beginner in C18 (I have a real love / hate relationship with C it feels like a language from 1952) 3V0 used to offer C tutorials for the Junebug here, you'll have to ask him if he still does. His website has some for download.
 
Thank you guys for your encuragements. Your advice is very apprechiated.

Swordfish basic:
Yes, that's the tool i'm using right now. I also looked into JAL, but the fish seems like it suits me better.

As for a pdf document "this is how I started", it would be great to have it as a junebug "official" document.
That would demand help from you guys though, to proof read, both for spelling/grammar errors, as well as factual errors(i still get confused to the point of tears from this:)).
Since english isn't my native language, the grammar/spelling gets really bad at times.

Again, thanks guys for taking the time to answer my questions. It's ok to smile and think "oh, i remember when I was new like that" :)
 
BASIC is great if English is your first language, it's got to be a beast otherwise. And as convenient as BASIC is as it can probably do what 99% of casual PIC programmers will use a PIC for.

It does support MPLAB if you want debug support but the Swordfish IDE is just so nice it's hard to go back to MPLABs editor (which really really could use a few tweaks)
 
Last edited:
Hello, I finally decided to jump in here and type something :D Im surprised no one ever talks about https://www.mikroe.com/en/books/picbook/picbook.htm

That is what got me started. You will surely learn a lot by jumping into that online book. Like Bill "blueroomelectronics" said

"The best examples are often in assembly as it's a 1:1 ratio (1 line code = 1 instruction)"

If you get into C and your code is "time sensitive" like things need to be done every uS on the uS (uS = Micro Second) then you have to use MPLABs "Stop Watch" and make sure timing is correct since a call in C is not 1 instruction cycle and can actually take about way more.

Anyway. Im going to start writing some nice C tutorials based on all i learned. The Tutorial will be based on C18 which has a free student edition (which is awesome).

The only thing i think i would need help in is subjects to cover.I might check out Gramo's site to see what and how he is making his tutorials and do the same for C18.

So just remember read up on what ever your making and have fun. It took me like 4-5 months to gather so much info.. i dream about PICs attacking AVRs :D
 
I recently got a junebug too, and had some trouble getting a LED to blink.This program will blink two LEDs on and off. I had gotten the first portion from Pommie, since my code didnt work, see here for more info:https://www.electro-tech-online.com/threads/need-some-help.42934/.


Code:
Device = 18F1320
Clock = 4 // 4MHz clock

Config OSC = INTIO2, WDT = OFF, LVP = OFF

OSCCON = $62        // select 4MHz internal clock
ADCON1  = $7f       //all digital

TRISA.7 = 1          //needed or else other LEDs will light
While True
          
    High (PORTA.6)
    Low (PORTA.0)
    DelayMS (1000)
    Low (PORTA.6)
    High (PORTA.0)
    DelayMS (1000) 
  
Wend
End
 
Last edited:
i dream about PICs attacking AVRs

PIC attacking AVR in GCBasic:D, or vice-versa depending on your viewpoint:p, or set as early defense warning for even suggesting Basic:eek:.

Code:
;PIC code
#chip 16f88,20

dir PortB.0 out
dir PortB.1 out

start:
set PortB.0 on
set PortB.1 off
wait 100 ms
set PortB.0 off
set PortB.1 on
wait 1 s
goto start


;Undocumented Atmel code (very limited functionality)
#chip mega168,8

dir PortB.0 out
dir PortB.1 out

start:
set PortB.0 on
set PortB.1 off
wait 100 ms
set PortB.0 off
set PortB.1 on
;compiler bug when using seconds for AVR
For waitsec = 1 to 4
	wait 250 ms
next
goto start
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top