Herzlich Willkommen, lieber Gast!
  Sie befinden sich hier:

  Forum » Assembler » PIC 16F84A Ampelschaltung

Forum | Hilfe | Team | Links | Impressum | > Suche < | Mitglieder | Registrieren | Einloggen
  Quicklinks: MSDN-Online || STL || clib Reference Grundlagen || Literatur || E-Books || Zubehör || > F.A.Q. < || Downloads   

Autor Thread - Seiten: > 1 <
000
22.02.2005, 17:42 Uhr
FloSoft
Medialer Over-Flow
(Administrator)


So nun funktioniert meine Ampel gescheit


ASM:

LIST P=PIC16F84A, F=INHX8M

#include <p16F84A.inc>

__CONFIG            _PWRTE_ON & _WDT_OFF & _XT_OSC

;******************************************************************************;
; Variablen                                                                    ;
;******************************************************************************;

irqh_w              equ                 0x0C
irqh_status         equ                 0x0D

ampel_status        equ                 0x22
ampel_position      equ                 0x23

wait_zaehler        equ                 0x24

;******************************************************************************;
; Defines                                                                      ;
;******************************************************************************;

#define             LED_STATUS_BLINKEN  PORTA, 0
#define             LED_STATUS_AUS      PORTA, 1
#define             LED_STATUS_AN       PORTA, 2
#define             LED_STATUS_PRESSED  PORTA, 3

#define             LED_A1_ROT          PORTB, 1
#define             LED_A1_GELB         PORTB, 2
#define             LED_A1_GRUEN        PORTB, 3

#define             LED_A2_ROT          PORTB, 5
#define             LED_A2_GELB         PORTB, 6
#define             LED_A2_GRUEN        PORTB, 7

#define             STATUS_AUS          ampel_status, 0
#define             STATUS_AN           ampel_status, 1
#define             STATUS_BLINKEN      ampel_status, 2

#define             POSITION_A          ampel_position, 0
#define             POSITION_B          ampel_position, 1
#define             POSITION_C          ampel_position, 2
#define             POSITION_D          ampel_position, 3


;******************************************************************************;
; Programm Beginn                                                              ;
;******************************************************************************;
                    org                 0x000
                    goto                INIT
          
;******************************************************************************;
; Interrupthandler                                                             ;
;******************************************************************************;
                    org                 0x004
                    bcf                 INTCON, GIE

                    movwf               irqh_w
                    movf                STATUS,w
                    movwf               irqh_status
          
                    call                IRQH

                    movf                irqh_status,w
                    movwf               STATUS
                    swapf               irqh_w,f
                    swapf               irqh_w,w

                    bsf                 INTCON, GIE

                    retfie

;******************************************************************************;
; Initialisierung                                                              ;
;******************************************************************************;

INIT:
                    clrwdt
                    bsf                 STATUS, RP0
                  
                    movlw               B'00000000' ; RA0-4 Input
                    movwf               TRISA
                  
                    movlw               B'00000001' ; RB0 Input, RB1-7 Output
                    movwf               TRISB
                  
                    movlw               B'11000100'
                    movwf               OPTION_REG

                    bcf                 STATUS, RP0
                    
                    movlw               D'113'
                    movwf               TMR0

                    clrf                PORTA
                    clrf                PORTB
                    
                    bsf                 INTCON, INTE
                    bsf                 INTCON, T0IE
                    bsf                 INTCON, GIE

                    call                MAIN
                    
                    goto                ENDE

;******************************************************************************;
; Hauptprogramm                                                                ;
;******************************************************************************;

MAIN:
                    clrwdt
                    call                AMPEL_BLINK

MAIN_LOOP:
                    call                AMPEL_ZEIGESTATUS

                    call                AMPEL_AUS
                    
                    btfsc               STATUS_AUS
                    goto                MAIN_SLEEP

                    btfsc               STATUS_AN
                    call                AMPEL_AN

                    btfsc               STATUS_BLINKEN
                    call                AMPEL_BLINKEN

                    goto                MAIN_ENDE
                    
MAIN_SLEEP:
                    call                WAIT
                    call                WAIT
                    goto                MAIN_ENDE

MAIN_ENDE:                    
                    goto                MAIN_LOOP
                    return

;******************************************************************************;
; Subroutine für Interrupthandler                                              ;
;******************************************************************************;

IRQH:
                    btfsc               INTCON, T0IF
                    call                IRQH_TIMER
                    
                    btfsc               INTCON, INTF
                    call                IRQH_RB0

                    return

IRQH_TIMER:
                    bcf                 INTCON, T0IF
                    incf                wait_zaehler
                    return

IRQH_RB0:
                    bcf                 INTCON, INTF
                    
                    btfsc               LED_STATUS_PRESSED
                    goto                IRQH_ENDE
                    
                    btfsc               STATUS_AUS
                    goto                IRQH_AN

                    btfsc               STATUS_AN
                    goto                IRQH_BLINK

                    btfsc               STATUS_BLINKEN
                    goto                IRQH_AUS
                    
                    goto                IRQH_ENDE

IRQH_AUS:
                    call                AMPEL_OFF
                    goto                IRQH_ENDE

IRQH_AN:
                    call                AMPEL_ON
                    goto                IRQH_ENDE

IRQH_BLINK:
                    call                AMPEL_BLINK
                    goto                IRQH_ENDE

IRQH_ENDE:
                    bsf                 LED_STATUS_PRESSED
                    return


;******************************************************************************;
; Subroutine für Timer                                                         ;
;******************************************************************************;

WAIT:          
                    clrf                  wait_zaehler
WAIT_LOOP:
                    btfss                  wait_zaehler, 7
                    goto                WAIT_LOOP
                    return

;******************************************************************************;
; Subroutine für Ampel: AUS                                                    ;
;******************************************************************************;

AMPEL_AUS:
                    bcf                 LED_A1_ROT
                    bcf                 LED_A1_GELB
                    bcf                 LED_A1_GRUEN

                    bcf                 LED_A2_ROT
                    bcf                 LED_A2_GELB
                    bcf                 LED_A2_GRUEN
                    return

;******************************************************************************;
; Subroutine für Ampel: AN                                                     ;
;******************************************************************************;

AMPEL_AN:
                    btfsc               POSITION_A
                    goto                AMPEL_AN_PA

                    btfsc               POSITION_B
                    goto                AMPEL_AN_PB

                    btfsc               POSITION_C
                    goto                AMPEL_AN_PC

                    btfsc               POSITION_D
                    goto                AMPEL_AN_PD

AMPEL_AN_PA:
                    bsf                 LED_A1_ROT
                    bsf                 LED_A2_GRUEN
                    
                    clrf                ampel_position
                    bsf                 POSITION_B
                    goto                AMPEL_AN_SLEEP

AMPEL_AN_PB:
                    bsf                 LED_A1_ROT
                    bsf                 LED_A1_GELB
                    bsf                 LED_A2_GELB

                    clrf                ampel_position
                    bsf                 POSITION_C
                    goto                AMPEL_AN_ENDE

AMPEL_AN_PC:
                    bsf                 LED_A1_GRUEN
                    bsf                 LED_A2_ROT
                    
                    clrf                ampel_position
                    bsf                 POSITION_D
                    goto                AMPEL_AN_SLEEP

AMPEL_AN_PD:
                    bsf                 LED_A1_GELB
                    bsf                 LED_A2_ROT
                    bsf                 LED_A2_GELB
                    
                    clrf                ampel_position
                    bsf                 POSITION_A
                    goto                AMPEL_AN_ENDE

AMPEL_AN_SLEEP:
                    call                WAIT
                    call                WAIT
                    call                WAIT

AMPEL_AN_ENDE:
                    call                WAIT
                    return

;******************************************************************************;
; Subroutine für Ampel: BLINKEN                                                ;
;******************************************************************************;

AMPEL_BLINKEN:
                    bcf                 LED_A2_GELB
                    call                WAIT
                    bsf                 LED_A2_GELB
                    call                WAIT
                    return

;******************************************************************************;
; Subroutine für Ampel: Ausschalten                                            ;
;******************************************************************************;

AMPEL_OFF:
                    clrf                ampel_status
                    bsf                 STATUS_AUS
                    return

;******************************************************************************;
; Subroutine für Ampel: Anschalten                                             ;
;******************************************************************************;

AMPEL_ON:
                    clrf                ampel_status
                    bsf                 STATUS_AN
                    clrf                ampel_position
                    bsf                 POSITION_A
                    return

;******************************************************************************;
; Subroutine für Ampel: auf Blinken schalten                                   ;
;******************************************************************************;

AMPEL_BLINK:
                    clrf                ampel_status
                    bsf                 STATUS_BLINKEN
                    return

;******************************************************************************;
; Subroutine für Ampel: Ampelstatus darstellen                                 ;
;******************************************************************************;

AMPEL_ZEIGESTATUS:
                    clrf                PORTA
                    
                    btfsc               STATUS_AUS
                    bsf                 LED_STATUS_AUS

                    btfsc               STATUS_AN
                    bsf                 LED_STATUS_AN

                    btfsc               STATUS_BLINKEN
                    bsf                 LED_STATUS_BLINKEN
                    
                    return

;******************************************************************************;

ENDE:
                    end
;******************************************************************************;



Bild dazu:



groß

Aufbau:

GND -> 680kOhm -> RB0 <- Taster <- +5V
RB1-3: Ampel 1 (LED's)
RB5-7: Ampel 2 (LED's)
RA0: Status Blinken (LED)
RA1: Status Aus (LED)
RA2: Status An (LED)
RA3: Status Wechseln (LED, ist an wenn taster gedrückt wurde bzw während Ampel Status ändert)

Man muss den Interrupteingang RB0 über einen (hohen) Widerstand mit Masse verbinden, sonst funktioniert der Taster nicht richtig, da der PIC sonst keinen gescheiten Unterschied zwischen "High"/"gedrückt" und "Low"/"nicht gedrückt" erkennt.
--
class God : public ChuckNorris { };

Dieser Post wurde am 22.03.2005 um 19:33 Uhr von FloSoft editiert.
 
Profil || Private Message || Suche Download || Zitatantwort || Editieren || Löschen || IP
001
22.02.2005, 19:38 Uhr
muhahahaha
Funsofts next Userpic model 2006 :D


coool gemacht
 
Profil || Private Message || Suche Download || Zitatantwort || Editieren || Löschen || IP
002
22.02.2005, 22:26 Uhr
FloSoft
Medialer Over-Flow
(Administrator)


hab auch ca 2 wochen dran rumgebastelt
--
class God : public ChuckNorris { };
 
Profil || Private Message || Suche Download || Zitatantwort || Editieren || Löschen || IP
003
23.02.2005, 06:42 Uhr
muhahahaha
Funsofts next Userpic model 2006 :D


 
Profil || Private Message || Suche Download || Zitatantwort || Editieren || Löschen || IP
004
23.02.2005, 15:40 Uhr
RedEagle



tolle sache...

Sowas müssenwa demnächst auch inna Schule machen... Freu mich schon
--
MFG RedEagle
 
Profil || Private Message || Suche Download || Zitatantwort || Editieren || Löschen || IP
005
23.02.2005, 16:35 Uhr
muhahahaha
Funsofts next Userpic model 2006 :D


das glaub ich hast den quelltext ja schon
 
Profil || Private Message || Suche Download || Zitatantwort || Editieren || Löschen || IP
006
23.02.2005, 16:51 Uhr
RedEagle



Ich glaub nicht, das mir das viel hilft, da wir bestimmt nicht das selbe Ampelsystem nehmen...

Außerdem macht selber-schreiben mehr spaß
--
MFG RedEagle
 
Profil || Private Message || Suche Download || Zitatantwort || Editieren || Löschen || IP
007
23.02.2005, 20:06 Uhr
FloSoft
Medialer Over-Flow
(Administrator)


wahrscheinlich benutzt ihr auch einen anderen y-controller
--
class God : public ChuckNorris { };
 
Profil || Private Message || Suche Download || Zitatantwort || Editieren || Löschen || IP
Seiten: > 1 <     [ Assembler ]  


ThWBoard 2.73 FloSoft-Edition
© by Paul Baecher & Felix Gonschorek (www.thwboard.de)

Anpassungen des Forums
© by Flo-Soft (www.flo-soft.de)

Sie sind Besucher: