AVR NooB

Status
Not open for further replies.
ok cool... ill make a nice pic device and give full source and code and schem later and test it out
 
ok im about to start working on this now. I just found my junebug.... my pickit 2 is dead right now so... anyway... Ill be using a 18F2525 a 2x16 LCD and a nice 3 way switch .... SparkFun Electronics - Surface Mount Navigation Switch

I made my own breakout board for it.... ANyway ill have pictures of my clock generator and source later today or tomorrow...
 
Hi Jason,

What's the clock speed on that 18F2525? With an 8-MHz clock you could toggle an output pin at 2-usec intervals to generate a 250-KHz clock signal;
Code:
loop
        movlw   b'00000001'     ; mask for RB0
        xorwf   LATB,F          ; toggle RB0 output
        bra     loop            ;
 
Last edited:
im doing it in C first and also i will have 4 speeds... 32khz, 1mhz, 4 mhz and 8 mhz output... im using the 18f2525 because its small and has lots of power... with a 10mhz external crystal and PLL thats 40mhz aka 10mips
 
This is what i have so far... have not tested it fully but LCD works lol .. so tired need a break...
Code:
/* *****************************************************************************
;                                                                             *
;    Filename:                     				                              *
;    Date:                                         	                          *
;    File Version: 001                                                        *
;                                                                             *
;    Author:   Jason Lopez                                                    *
;    Company:  AtomSoft                                                       *
;                                                                             *
;***************************************************************************** */

#include <p18f2525.h>
#include <delays.h>
#include "lcd.h"

#pragma config WDT = OFF, LVP = OFF, OSC = HSPLL

/************************************
Prototypes
*************************************/
void main(void);
const unsigned char SpeedA[]="Speed: 32 KHz\0";
const unsigned char SpeedB[]="Speed: 1 MHz \0";
const unsigned char SpeedC[]="Speed: 4 MHz \0";
const unsigned char SpeedD[]="Speed: 8 MHz \0";

void h_isr (void);
void InterruptVectorHigh (void);
void initISR(void);
void Speed1(void);
void Speed2(void);
void Speed3(void);
void Speed4(void);
/************************************
VARIABLES
*************************************/
char x = 0;
char speed=0;
char done=0;

#define btnUp  PORTBbits.RB1
#define btnDwn PORTBbits.RB2


/************************************
Interrupt Vectors
*************************************/
#pragma code InterruptVectorHigh = 0x08
void InterruptVectorHigh (void)
{
  _asm
    goto h_isr //jump to interrupt routine
  _endasm
}
#pragma code
/************************************
Rx Intterup (HIGH)
*************************************/
#pragma interrupt h_isr
void h_isr (void){
	//Clear the ISR Flag
	INTCONbits.INT0IF = 0;
	while(PORTBbits.RB0);
	if(done){
		done = 0;
	} else {
		done = 1;
	}

	Delay10KTCYx(20);


}

/************************************
Main
*************************************/
void main(void){

	TRISA = TRISB = TRISC = 0x00;
	LATA = LATB = LATC = 0x00;
	ADCON1 = 0x0F;

	initLCD();
	initISR();



	while(1){
		switch(speed){
			case 0:
				Speed1();
				break;
			case 1:
				Speed2();
				break;
			case 2:
				Speed3();
				break;
			case 3:
				Speed4();
				break;
		}	

		LCD_LINE(2);
		LCD_STR((unsigned rom char*)"Stopped......\0");

		while(done){
			if(btnUp){
				while(btnUp);
				if(speed == 4) 
					speed = 0;
				else
					speed++;
				
				LCD_LINE(1);
				switch(speed){
					case 0:	
						LCD_STR2(SpeedA);
						break;
					case 1:	
						LCD_STR2(SpeedB);
						break;
					case 2:	
						LCD_STR2(SpeedC);
						break;
					case 3:	
						LCD_STR2(SpeedD);
						break;
				}
				LCD_LINE(2);
				LCD_STR((unsigned rom char*)"Stopped......\0");

				Delay10KTCYx(200);
			}
			if(btnDwn){
				while(btnDwn);
				if(speed == 0)
					speed = 3;
				else
					speed--;

				LCD_LINE(1);
				switch(speed){
					case 0:	
						LCD_STR2(SpeedA);
						break;
					case 1:	
						LCD_STR2(SpeedB);
						break;
					case 2:	
						LCD_STR2(SpeedC);
						break;
					case 3:	
						LCD_STR2(SpeedD);
						break;
				}
				LCD_LINE(2);
				LCD_STR((unsigned rom char*)"Stopped......\0");

				Delay10KTCYx(200);
			}
		}	
	}
}
void Speed1(void){ //32khz
	LCD_LINE(1);
	LCD_STR((unsigned rom char*)"Speed: 32 KHz \0");
	LCD_LINE(2);
	LCD_STR((unsigned rom char*)"Running.....  \0");
	while(!done){
		Delay10TCYx(34);
		LATCbits.LATC4 = 1;
		Delay10TCYx(34);
		LATCbits.LATC4 = 0;
	}
}
void Speed2(void){ //1mhz
	LCD_LINE(1);
	LCD_STR((unsigned rom char*)"Speed: 1 Mhz  \0");
	LCD_LINE(2);
	LCD_STR((unsigned rom char*)"Running.....  \0");
	while(!done){
		Delay10TCY();
		LATCbits.LATC4 = 1;
		Delay10TCY();
		LATCbits.LATC4 = 0;
	}
}
void Speed3(void){ //4mhz
	LCD_LINE(1);
	LCD_STR((unsigned rom char*)"Speed: 4 Mhz  \0");
	LCD_LINE(2);
	LCD_STR((unsigned rom char*)"Running.....  \0");
	while(!done){
		Nop();
		Nop();
		LATCbits.LATC4 = 1;
		Nop();
		Nop();
		LATCbits.LATC4 = 0;
	}
}
void Speed4(void){ //8mhz
	LCD_LINE(1);
	LCD_STR((unsigned rom char*)"Speed: 8 Mhz  \0");
	LCD_LINE(2);
	LCD_STR((unsigned rom char*)"Running.....  \0");
	while(!done){
		Nop();
		LATCbits.LATC4 = 1;
		Nop();
		LATCbits.LATC4 = 0;
	}
}
void initISR(void){
	INTCON = 0b11010000;
	INTCON2 = 0b11000000;	
	TRISBbits.TRISB0 = 1;	
	TRISBbits.TRISB1 = 1;	
	TRISBbits.TRISB2 = 1;	
}
 
well this is a failed process heh... I am going to buy a few AVRs and see if i can work with new ones.... I now have 3 AVRs down... 1 ATMEGA88 and 2 ATTINY2313 This sux!!! i bought this programmer to avoid things like this lol and look ! Anyway thank goodness these things are cheap..
 
?! What the heck are you doing Atom? You've used pics for a while now and they're not much different from them, I started on AVR's brand spanking new and I've never lost a single chip, I fried a single I/O pin on one but that's it. I wouldn't touch any other chips until you figure out EXACTLY what is going on with the ones you have cause you're just gonna brick more until you do. If you're getting flustered abotu the whole ordeal stop what you're doing and walk away from it for a couple days till you can come back to it with a clear mind and start the debugging process over again. I had to do this several times while I was first learning microcontrollers.
 
heh... i want to order a new AVR mainly to ensure its not a faulty Dragon. If i can get a new AVR working then i know its my ICs ... i did something to em not sure... Ill give it a day or so...
 
Something as complex as the Dragon is going to either work, or not; they don't generally have complex failure modes.
I thought I 'bricked' two ATAVRISP programmers, and bought an STK500 dev kit, which does suit my needs better. But I've since after careful attention to all the written words about them resurrected both AVRISP programmers, actually they both were shipped free to users here. The error was I wasn't properly timing the reset sequence to get the ATAVRISP into it's internal programming update mode. I was so upset at the time that I wasn't waiting the single additional second required to put it in the proper mode for internal chip updating. 99.9% of the time it's user error. Finding out that error is first and foremost.
 
Last edited:
Im going to wait until i clean my whole area before working with AVRs... i might even setup a laptop i have here for AVR only work. This way i can have a clean start with software and hardware and a clean environment.
 
BTW, because of these posts I did a little reading up yesterday, if you're not affraid of surface mount, look at the Xmega line... 16 bit core, 12bit ADC _AND_ DAC. I just don't need em yet, but they look nice.
 
OMG i think i fixed it!!! simplest thing ever..... i read up on AVR some more and noticed it has a internal 36pf cap on xtal pins... so i tied a 1k resistor to XTAL1 pin and VCC and poof! i can read/erase/write
 
yeah i can confirm it works now. I can now program and change fuses ... I made a simple blink code in C and works like a charm.... DEBUGGING works and Actual Programming!! Yes! so happy....

Code:
#define	F_CPU 8000000UL
#include <avr/io.h>
#include <util/delay.h>
#include <stdio.h>

#define LED		0

#define sbi(var, mask)   ((var) |= (uint8_t)(1 << mask))
#define cbi(var, mask)   ((var) &= (uint8_t)~(1 << mask))

int main(void)
{

	DDRB = 0xff;				//Data DiRection PORTB = OUTPUTS


	while(1)
	{
		sbi(PORTB,LED);
		_delay_ms(500);
		cbi(PORTB,LED);
		_delay_ms(500);

	}

}
 
Very nice.

So is there any way to indicate fuse settings from within source programs like we do on the PIC?
 
im not sure but i dont think so... but im sure with the 1k resistor there or a a crystal you can simply read the fuse from within avr studio
 
Hey guys this is REV1 of my AVR Dragon Adapter.... WITH NEW LOGO... plz dont copy it heh... I know have a second part to this adapter but it isnt done yet heh...

 

Attachments

  • AVRISP.jpg
    169.6 KB · Views: 552
Last edited:
The only way you could reprogram the fuses in circuit would be to have a second MCU bring the one you want to change into programming mode. The programming protocol is fully described, thought I'm not sure why you'd want to do this.

Atom, while I'm glad you can reprogram your chips now, I'm not exactly sure how that actually worked. What does there being an internal capacitance on the Xtal pin and tieing it via a resistor to VCC allow it to be reprogrammed? Also, what fuses did you have set that weren't allowing it to run? If it were the external oscilator fuse as you described earlier feeding it a clock on the xtal line should have worked.
 
ok ill try to explain it as good as i can heh

Once you set a FUSE as noted before you have to have that clock running to reprogram it... I think i had EXT CLOCK.... so i tried to make a external clock but didnt work so i made a External RC Clock using just 1 resistor since it has a internal cap.
 
Last edited:
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…