Kod: Markera allt
#define Read1 PORTE.F2
#define Read2 PORTE.F1
#define Read3 PORTE.F0
#define Read4 PORTB.F5
#define Read5 PORTB.F4
#define Read6 PORTB.F3
#define Led1 PORTB.F0
#define Led2 PORTA.F7
#define Led3 PORTA.F6
#define Led4 PORTA.F5
#define Led5 PORTA.F4
#define Led6 PORTA.F3
#define H1A PORTD.F2
#define H1B PORTD.F1
#define H2A PORTD.F0
#define H2B PORTC.F7
#define H3A PORTC.F6
#define H3B PORTC.F5
#define H4A PORTC.F2
#define H4B PORTC.F1
#define H5A PORTC.F0
#define H5B PORTA.F0
#define H6A PORTA.F1
#define H6B PORTA.F2
#define BTN_up PORTB.F1
#define BTN_down PORTB.F2
#define BTN_Start PORTC.F4
int i,a=0,k;
int time, nbr;
//LCD module connection
sbit LCD_RS at RD7_bit;
sbit LCD_EN at RD6_bit;
sbit LCD_D4 at RD5_bit;
sbit LCD_D5 at RD4_bit;
sbit LCD_D6 at RD3_bit;
sbit LCD_D7 at RC3_bit;
sbit LCD_RS_Direction at TRISD7_bit;
sbit LCD_EN_Direction at TRISD6_bit;
sbit LCD_D4_Direction at TRISD5_bit;
sbit LCD_D5_Direction at TRISD4_bit;
sbit LCD_D6_Direction at TRISD3_bit;
sbit LCD_D7_Direction at TRISC3_bit;
//End LCD module connection
void InitMain(){
TRISA=0b00000000;
TRISB=0b00111110;
TRISC=0b00010000;
TRISD=0b00000000;
TRISE=0b00000111;
ANSELA=0b00000000;
ANSELB=0b00000000;
ANSELD=0b00000000;
ANSELE=0b00000000;
OSCCON=0b01101010; //Oscillator set to 4MHz
H1A=0;
H1B=0;
H2A=0;
H2B=0;
H3A=0;
H3B=0;
H4A=0;
H4B=0;
H5A=0;
H5B=0;
H6A=0;
H6B=0;
LCD_Init(); //LCD startup
LCD_Cmd(_LCD_CURSOR_OFF);
Delay_ms(200);
Lcd_out(1,1,"AXIS IR Tester");
Lcd_out(2,1,"KS2018 R1.0");
for(i=0; i<3; i++){
Led1=0;
Led2=0;
Led3=0;
Led4=0;
Led5=0;
Led6=0;
Delay_ms(30);
Led1=1;
Led2=1;
Led3=1;
Led4=1;
Led5=1;
Led6=1;
Delay_ms(30);
}
}
void Switch(int n){
H1A=1;
H1B=0;
while(a<=n){
delay_ms(1);
a++;
}
a=0;
H1A=0;
H1B=0;
Delay_ms(50);
H1A=0;
H1B=1;
while(a<=n){
Delay_ms(1);
a++;
}
a=0;
H1A=0;
H1B=0;
delay_ms(50);
//-----------------------------------------------
H2A=1;
H2B=0;
while(a<=n){
delay_ms(1);
a++;
}
a=0;
H2A=0;
H2B=0;
Delay_ms(50);
H2A=0;
H2B=1;
while(a<=n){
Delay_ms(1);
a++;
}
a=0;
H2A=0;
H2B=0;
delay_ms(50);
//-----------------------------------------------
H3A=1;
H3B=0;
while(a<=n){
delay_ms(1);
a++;
}
a=0;
H3A=0;
H3B=0;
Delay_ms(50);
H3A=0;
H3B=1;
while(a<=n){
Delay_ms(1);
a++;
}
a=0;
H3A=0;
H3B=0;
delay_ms(50);
//-----------------------------------------------
H4A=1;
H2B=0;
while(a<=n){
delay_ms(1);
a++;
}
a=0;
H4A=0;
H4B=0;
Delay_ms(50);
H4A=0;
H4B=1;
while(a<=n){
Delay_ms(1);
a++;
}
a=0;
H4A=0;
H4B=0;
delay_ms(50);
//-----------------------------------------------
H5A=1;
H5B=0;
while(a<=n){
delay_ms(1);
a++;
}
a=0;
H5A=0;
H5B=0;
Delay_ms(50);
H5A=0;
H5B=1;
while(a<=n){
Delay_ms(1);
a++;
}
a=0;
H5A=0;
H5B=0;
delay_ms(50);
//-----------------------------------------------
H6A=1;
H6B=0;
while(a<=n){
delay_ms(1);
a++;
}
a=0;
H6A=0;
H6B=0;
Delay_ms(50);
H6A=0;
H6B=1;
while(a<=n){
Delay_ms(1);
a++;
}
a=0;
H6A=0;
H6B=0;
delay_ms(50);
}
void Setting(){
Lcd_out(1,1,"Set switch time");
Lcd_out(2,1,"press + or -");
while(BTN_Start==1){
if(BTN_up==0){
Delay_ms(50);
if(BTN_up==0)
k+100;
}
if(BTN_down==0){
Delay_ms(50);
if(BTN_down==0)
k-100;
}
if((BTN_down==0||BTN_up==0)&&(100<=k<=300)){
k=k;
}
Lcd_Cmd(_LCD_CLEAR);
Lcd_out(1,1,"Switch time= ");
Lcd_Out(1,13,k);
while(1){
}
}
Lcd_out(1,1,"Set nbr cycles");
Lcd_out(2,1,"press + or -");
Lcd_out(1,1,"Press start");
}
void test(){
if (BTN_Start==0){
Lcd_out(1,1,"Start");
while(1){}
}
if (BTN_up==0){
Lcd_out(1,1,"upp");
while(1){}
}
if (BTN_down==0){
Lcd_out(1,1,"ner");
while(1){}
} }
void main() {
InitMain();
test();
// Switch(100);
//Setting();
}