Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
loop
movlw b'00000001' ; mask for RB0
xorwf LATB,F ; toggle RB0 output
bra loop ;
/* *****************************************************************************
; *
; 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;
}
#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);
}
}